@@ -816,7 +816,7 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
816
816
817
817
if self .dtype .kind in ["m" , "M" ]:
818
818
self = cast ("DatetimeArray | TimedeltaArray" , self )
819
- values = values ._as_unit (self ._unit )
819
+ values = values .as_unit (self .unit )
820
820
821
821
try :
822
822
self ._check_compatible_with (values )
@@ -1116,7 +1116,7 @@ def _add_datetimelike_scalar(self, other) -> DatetimeArray:
1116
1116
# i.e. np.datetime64("NaT")
1117
1117
# In this case we specifically interpret NaT as a datetime, not
1118
1118
# the timedelta interpretation we would get by returning self + NaT
1119
- result = self ._ndarray + NaT .to_datetime64 ().astype (f"M8[{ self ._unit } ]" )
1119
+ result = self ._ndarray + NaT .to_datetime64 ().astype (f"M8[{ self .unit } ]" )
1120
1120
# Preserve our resolution
1121
1121
return DatetimeArray ._simple_new (result , dtype = result .dtype )
1122
1122
@@ -1128,10 +1128,10 @@ def _add_datetimelike_scalar(self, other) -> DatetimeArray:
1128
1128
result = checked_add_with_arr (
1129
1129
self .asi8 , other_i8 , arr_mask = self ._isnan , b_mask = o_mask
1130
1130
)
1131
- res_values = result .view (f"M8[{ self ._unit } ]" )
1131
+ res_values = result .view (f"M8[{ self .unit } ]" )
1132
1132
1133
- dtype = tz_to_dtype (tz = other .tz , unit = self ._unit )
1134
- res_values = result .view (f"M8[{ self ._unit } ]" )
1133
+ dtype = tz_to_dtype (tz = other .tz , unit = self .unit )
1134
+ res_values = result .view (f"M8[{ self .unit } ]" )
1135
1135
new_freq = self ._get_arithmetic_result_freq (other )
1136
1136
return DatetimeArray ._simple_new (res_values , dtype = dtype , freq = new_freq )
1137
1137
@@ -1191,7 +1191,7 @@ def _sub_datetimelike(self, other: Timestamp | DatetimeArray) -> TimedeltaArray:
1191
1191
res_values = checked_add_with_arr (
1192
1192
self .asi8 , - other_i8 , arr_mask = self ._isnan , b_mask = o_mask
1193
1193
)
1194
- res_m8 = res_values .view (f"timedelta64[{ self ._unit } ]" )
1194
+ res_m8 = res_values .view (f"timedelta64[{ self .unit } ]" )
1195
1195
1196
1196
new_freq = self ._get_arithmetic_result_freq (other )
1197
1197
return TimedeltaArray ._simple_new (res_m8 , dtype = res_m8 .dtype , freq = new_freq )
@@ -1989,13 +1989,13 @@ def _creso(self) -> int:
1989
1989
return get_unit_from_dtype (self ._ndarray .dtype )
1990
1990
1991
1991
@cache_readonly
1992
- def _unit (self ) -> str :
1992
+ def unit (self ) -> str :
1993
1993
# e.g. "ns", "us", "ms"
1994
1994
# error: Argument 1 to "dtype_to_unit" has incompatible type
1995
1995
# "ExtensionDtype"; expected "Union[DatetimeTZDtype, dtype[Any]]"
1996
1996
return dtype_to_unit (self .dtype ) # type: ignore[arg-type]
1997
1997
1998
- def _as_unit (self : TimelikeOpsT , unit : str ) -> TimelikeOpsT :
1998
+ def as_unit (self : TimelikeOpsT , unit : str ) -> TimelikeOpsT :
1999
1999
dtype = np .dtype (f"{ self .dtype .kind } 8[{ unit } ]" )
2000
2000
new_values = astype_overflowsafe (self ._ndarray , dtype , round_ok = True )
2001
2001
@@ -2017,9 +2017,9 @@ def _ensure_matching_resos(self, other):
2017
2017
if self ._creso != other ._creso :
2018
2018
# Just as with Timestamp/Timedelta, we cast to the higher resolution
2019
2019
if self ._creso < other ._creso :
2020
- self = self ._as_unit (other ._unit )
2020
+ self = self .as_unit (other .unit )
2021
2021
else :
2022
- other = other ._as_unit (self ._unit )
2022
+ other = other .as_unit (self .unit )
2023
2023
return self , other
2024
2024
2025
2025
# --------------------------------------------------------------
0 commit comments