Skip to content

Commit 7d40d3e

Browse files
authored
CLN: remove rebox_native (#37608)
1 parent 67b087f commit 7d40d3e

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

pandas/core/arrays/datetimelike.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def _rebox_native(cls, value: int) -> Union[int, np.datetime64, np.timedelta64]:
151151
"""
152152
raise AbstractMethodError(cls)
153153

154-
def _unbox_scalar(self, value: DTScalarOrNaT, setitem: bool = False) -> int:
154+
def _unbox_scalar(
155+
self, value: DTScalarOrNaT, setitem: bool = False
156+
) -> Union[np.int64, np.datetime64, np.timedelta64]:
155157
"""
156158
Unbox the integer value of a scalar `value`.
157159
@@ -636,7 +638,6 @@ def _unbox(
636638
"""
637639
if lib.is_scalar(other):
638640
other = self._unbox_scalar(other, setitem=setitem)
639-
other = self._rebox_native(other)
640641
else:
641642
# same type as self
642643
self._check_compatible_with(other, setitem=setitem)

pandas/core/arrays/datetimes.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,13 @@ def _generate_range(
454454
# -----------------------------------------------------------------
455455
# DatetimeLike Interface
456456

457-
@classmethod
458-
def _rebox_native(cls, value: int) -> np.datetime64:
459-
return np.int64(value).view("M8[ns]")
460-
461-
def _unbox_scalar(self, value, setitem: bool = False):
457+
def _unbox_scalar(self, value, setitem: bool = False) -> np.datetime64:
462458
if not isinstance(value, self._scalar_type) and value is not NaT:
463459
raise ValueError("'value' should be a Timestamp.")
464460
if not isna(value):
465461
self._check_compatible_with(value, setitem=setitem)
466-
return value.value
462+
return value.asm8
463+
return np.datetime64(value.value, "ns")
467464

468465
def _scalar_from_string(self, value):
469466
return Timestamp(value, tz=self.tz)

pandas/core/arrays/period.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,14 @@ def _generate_range(cls, start, end, periods, freq, fields):
260260
# -----------------------------------------------------------------
261261
# DatetimeLike Interface
262262

263-
@classmethod
264-
def _rebox_native(cls, value: int) -> np.int64:
265-
return np.int64(value)
266-
267263
def _unbox_scalar(
268264
self, value: Union[Period, NaTType], setitem: bool = False
269265
) -> int:
270266
if value is NaT:
271-
return value.value
267+
return np.int64(value.value)
272268
elif isinstance(value, self._scalar_type):
273269
self._check_compatible_with(value, setitem=setitem)
274-
return value.ordinal
270+
return np.int64(value.ordinal)
275271
else:
276272
raise ValueError(f"'value' should be a Period. Got '{value}' instead.")
277273

pandas/core/arrays/timedeltas.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,11 @@ def _generate_range(cls, start, end, periods, freq, closed=None):
301301
# ----------------------------------------------------------------
302302
# DatetimeLike Interface
303303

304-
@classmethod
305-
def _rebox_native(cls, value: int) -> np.timedelta64:
306-
return np.int64(value).view("m8[ns]")
307-
308-
def _unbox_scalar(self, value, setitem: bool = False):
304+
def _unbox_scalar(self, value, setitem: bool = False) -> np.timedelta64:
309305
if not isinstance(value, self._scalar_type) and value is not NaT:
310306
raise ValueError("'value' should be a Timedelta.")
311307
self._check_compatible_with(value, setitem=setitem)
312-
return value.value
308+
return np.timedelta64(value.value, "ns")
313309

314310
def _scalar_from_string(self, value):
315311
return Timedelta(value)

pandas/tests/arrays/test_datetimelike.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ def test_unbox_scalar(self):
191191
data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9
192192
arr = self.array_cls(data, freq="D")
193193
result = arr._unbox_scalar(arr[0])
194-
assert isinstance(result, int)
194+
expected = arr._data.dtype.type
195+
assert isinstance(result, expected)
195196

196197
result = arr._unbox_scalar(pd.NaT)
197-
assert isinstance(result, int)
198+
assert isinstance(result, expected)
198199

199200
msg = f"'value' should be a {self.dtype.__name__}."
200201
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)