Merged
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,7 +144,7 @@ Numeric

Conversion
^^^^^^^^^^
-
- Bug in :meth:`ArrowDtype.numpy_dtype` returning nanosecond units for non-nanosecond ``pyarrow.timestamp`` and ``pyarrow.duration`` types (:issue:`51800`)
-

Strings
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -148,6 +148,18 @@ 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_timestamp(self.pyarrow_dtype):
# pa.timestamp(unit).to_pandas_dtype() returns ns units
# regardless of the pyarrow timestamp units.
# This can be removed if/when pyarrow addresses it:
# https://.com/apache/arrow/issues/34462
return np.dtype(f"datetime64[{self.pyarrow_dtype.unit}]")
if pa.types.is_duration(self.pyarrow_dtype):
# pa.duration(unit).to_pandas_dtype() returns ns units
# regardless of the pyarrow duration units
# This can be removed if/when pyarrow addresses it:
# https://.com/apache/arrow/issues/34462
return np.dtype(f"timedelta64[{self.pyarrow_dtype.unit}]")
if pa.types.is_string(self.pyarrow_dtype):
# pa.string().to_pandas_dtype() = object which we don't want
return np.dtype(str)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -640,11 +640,7 @@ def test_get_common_dtype(self, dtype, request):
if (
pa.types.is_date(pa_dtype)
or pa.types.is_time(pa_dtype)
or (
pa.types.is_timestamp(pa_dtype)
and (pa_dtype.unit != "ns" or pa_dtype.tz is not None)
)
or (pa.types.is_duration(pa_dtype) and pa_dtype.unit != "ns")
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None)
or pa.types.is_binary(pa_dtype)
or pa.types.is_decimal(pa_dtype)
):
Expand Down