Skip to content

Commit 447249a

Browse files
authored
BUG: Fix inconsistent datetime types between calamine and openpyxl readers (#59186) (#63318)
1 parent 66e22c5 commit 447249a

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

pandas/io/excel/_calamine.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from pandas.compat._optional import import_optional_dependency
1616
from pandas.util._decorators import doc
1717

18-
import pandas as pd
1918
from pandas.core.shared_docs import _shared_docs
2019

2120
from pandas.io.excel._base import BaseExcelReader
@@ -107,10 +106,12 @@ def _convert_cell(value: _CellValue) -> Scalar | NaTType | time:
107106
return val
108107
else:
109108
return value
109+
elif isinstance(value, (datetime, timedelta)):
110+
# Return as-is to match openpyxl behavior (GH#59186)
111+
return value
110112
elif isinstance(value, date):
111-
return pd.Timestamp(value)
112-
elif isinstance(value, timedelta):
113-
return pd.Timedelta(value)
113+
# Convert date to datetime to match openpyxl behavior (GH#59186)
114+
return datetime(value.year, value.month, value.day)
114115
elif isinstance(value, time):
115116
return value
116117

pandas/tests/io/excel/test_readers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ def df_ref(datapath):
135135

136136

137137
def get_exp_unit(read_ext: str, engine: str | None) -> str:
138-
unit = "us"
139-
if read_ext == ".ods" and engine == "odf":
140-
pass
141-
elif (read_ext == ".ods") ^ (engine == "calamine"):
142-
unit = "s"
143-
return unit
138+
return "us"
144139

145140

146141
def adjust_expected(expected: DataFrame, read_ext: str, engine: str | None) -> None:

0 commit comments

Comments
 (0)