-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: ArrowDtype.type #51307
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
API: ArrowDtype.type #51307
Changes from 1 commit
94722db
9717e23
bf6dda9
9174758
9d455dd
afd8745
d849ad3
7ce4375
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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import ( | ||
date, | ||
datetime, | ||
time, | ||
timedelta, | ||
) | ||
import re | ||
|
||
import numpy as np | ||
|
||
from pandas._libs.tslibs import ( | ||
Timedelta, | ||
Timestamp, | ||
) | ||
from pandas._typing import ( | ||
TYPE_CHECKING, | ||
DtypeObj, | ||
|
@@ -90,7 +100,36 @@ def type(self): | |
""" | ||
Returns pyarrow.DataType. | ||
""" | ||
return type(self.pyarrow_dtype) | ||
pa_type = self.pyarrow_dtype | ||
if pa.types.is_integer(pa_type): | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return int | ||
elif pa.types.is_floating(pa_type): | ||
return float | ||
elif pa.types.is_string(pa_type): | ||
return str | ||
elif pa.types.is_binary(pa_type): | ||
return bytes | ||
elif pa.types.is_boolean(pa_type): | ||
return bool | ||
elif pa.types.is_duration(pa_type): | ||
if pa_type.unit == "ns": | ||
return Timedelta | ||
else: | ||
return timedelta | ||
elif pa.types.is_timestamp(pa_type): | ||
if pa_type.unit == "ns": | ||
return Timestamp | ||
else: | ||
return datetime | ||
Comment on lines
+121
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not for this PR, just noting from seeing the diff) FWIW, now Timestamp supports multiple resolutions, we should make it return a Timestamp for all cases, I think (it's something we should also do on the pyarrow side, but on the short term it will be easier done on the pandas side to ensure consistent behaviour across pyarrow versions) |
||
elif pa.types.is_date(pa_type): | ||
return date | ||
elif pa.types.is_time(pa_type): | ||
return time | ||
elif pa.types.is_null(pa_type): | ||
# TODO: None? pd.NA? pa.null? | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return type(pa_type) | ||
else: | ||
raise NotImplementedError(pa_type) | ||
|
||
@property | ||
def name(self) -> str: # type: ignore[override] | ||
|
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.
This docstring will need updating