Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pandas/io/excel/_calamine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pandas.compat._optional import import_optional_dependency
from pandas.util._decorators import doc

import pandas as pd
from pandas.core.shared_docs import _shared_docs

from pandas.io.excel._base import BaseExcelReader
Expand Down Expand Up @@ -107,10 +106,16 @@ def _convert_cell(value: _CellValue) -> Scalar | NaTType | time:
return val
else:
return value
elif isinstance(value, datetime):
# Return datetime.datetime as-is to match openpyxl behavior (GH#59186)
return value
elif isinstance(value, date):
return pd.Timestamp(value)
# Convert date to datetime to match openpyxl behavior (GH#59186)
return datetime(value.year, value.month, value.day)
elif isinstance(value, timedelta):
return pd.Timedelta(value)
# Return datetime.timedelta as-is to match openpyxl behavior (GH#59186)
# (previously returned pd.Timedelta)
return value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you combine this branch with the isinstance(value, datetime) branch by combining the isinstance checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

elif isinstance(value, time):
return value

Expand Down
7 changes: 1 addition & 6 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,7 @@ def df_ref(datapath):


def get_exp_unit(read_ext: str, engine: str | None) -> str:
unit = "us"
if read_ext == ".ods" and engine == "odf":
pass
elif (read_ext == ".ods") ^ (engine == "calamine"):
unit = "s"
return unit
return "us"


def adjust_expected(expected: DataFrame, read_ext: str, engine: str | None) -> None:
Expand Down
Loading