-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
When getting the numpy datatype, return datetime64[D] for pa.Date32 and return datetime64[ms] for pa.Date64 #62913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
When getting the numpy datatype, return datetime64[D] for pa.Date32 and return datetime64[ms] for pa.Date64 #62913
Conversation
…ly one common type. Return objects for date32 and date64 types when converting those types to numpy types.
pandas/core/dtypes/common.py
Outdated
| # try a pyarrow dtype | ||
| from pandas.core.dtypes.dtypes import ArrowDtype | ||
| if isinstance(dtype, ArrowDtype): | ||
| return ArrowDtype(dtype) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
pandas/core/dtypes/dtypes.py
Outdated
| 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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
pandas/core/dtypes/dtypes.py
Outdated
| ): | ||
| # date32 and date64 are pyarrow timestamps but do not have a | ||
| # corresponding numpy dtype. | ||
| return np.dtype(object) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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]?
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
…ests in test_arrow
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
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.