Skip to content

Conversation

@linicole74
Copy link

@linicole74 linicole74 commented Oct 30, 2025

When getting the numpy datatype, return datetime64[D] for pa.Date32 and return datetime64[ms] for pa.Date64.

pa.Date64 still will not roundtrip properly since either both datetime64[ms] and date64 must convert to date64, or both datetime64[ms] and date64 must convert to timestamp64[ms].

#62343

nli307 added 2 commits October 29, 2025 20:42
…ly one common type. Return objects for date32 and date64 types when converting those types to numpy types.
# try a pyarrow dtype
from pandas.core.dtypes.dtypes import ArrowDtype
if isinstance(dtype, ArrowDtype):
return ArrowDtype(dtype)
Copy link
Member

Choose a reason for hiding this comment

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

do we ever get here? Seems like these cases would be caught above

Copy link
Author

Choose a reason for hiding this comment

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

You're right, removed this

if pa.types.is_date32(self.pyarrow_dtype) or pa.types.is_date64(
self.pyarrow_dtype
):
# date32 and date64 are pyarrow timestamps but do not have a
Copy link
Member

Choose a reason for hiding this comment

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

nitpick they are not "pyarrow timestamps"

Copy link
Author

Choose a reason for hiding this comment

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

Removed comment and also replaced code

):
# date32 and date64 are pyarrow timestamps but do not have a
# corresponding numpy dtype.
return np.dtype(object)
Copy link
Member

Choose a reason for hiding this comment

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

np.datetime64[D] might be more reasonable?

Copy link
Author

Choose a reason for hiding this comment

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

Replaced date32 with np.datetime64[D], good catch!

Copy link
Author

Choose a reason for hiding this comment

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

@jbrockmendel
Should date64 also be cast to np.datetime64[D], or should it be kept as a timestamp[ms]?

@linicole74
Copy link
Author

pre-commit.ci autofix

@linicole74 linicole74 changed the title When finding the common type, return the original type if there is on… When getting the numpy datatype, return datetime64[D] for pa.Date32 and return datetime64[ms] for pa.Date64 Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: _get_common_dtype with date32[pyarrow] and null[pyarrow]

2 participants