-
-
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?
Changes from 2 commits
5071e11
38ba1bd
829f8a0
4b0a90c
9241196
0f31992
3fea3e0
ac77415
608a43d
d3680a1
7ff8825
220e290
a187f86
74552ce
495f85e
a4f89dd
ea3f900
4cff244
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2277,6 +2277,12 @@ def name(self) -> str: # type: ignore[override] | |
| @cache_readonly | ||
| def numpy_dtype(self) -> np.dtype: | ||
| """Return an instance of the related numpy dtype""" | ||
| 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 | ||
|
||
| # corresponding numpy dtype. | ||
| return np.dtype(object) | ||
|
||
| if pa.types.is_timestamp(self.pyarrow_dtype): | ||
| # pa.timestamp(unit).to_pandas_dtype() returns ns units | ||
| # regardless of the pyarrow timestamp units. | ||
|
|
@@ -2453,6 +2459,18 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None: | |
|
|
||
| null_dtype = type(self)(pa.null()) | ||
|
|
||
| # Cover cases where numpy does not have a corresponding dtype, but | ||
| # only one non-null dtype is received, or all dtypes are null. | ||
| single_dtype = { | ||
| dtype | ||
| for dtype in dtypes | ||
| if dtype != null_dtype | ||
| } | ||
| if len(single_dtype) == 0: | ||
| return null_dtype | ||
| if len(single_dtype) == 1: | ||
| return single_dtype.pop() | ||
|
|
||
| new_dtype = find_common_type( | ||
| [ | ||
| dtype.numpy_dtype if isinstance(dtype, ArrowDtype) else 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