Skip to content

Commit f0e3f0a

Browse files
authored
BUG: TDA.__floordiv__ with NaT (#35583)
* BUG: TDA.__floordiv__ with NaT * whatsnew
1 parent b05fdcd commit f0e3f0a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

doc/source/whatsnew/v1.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Datetimelike
6464

6565
Timedelta
6666
^^^^^^^^^
67-
67+
- Bug in :class:`TimedeltaIndex`, :class:`Series`, and :class:`DataFrame` floor-division with ``timedelta64`` dtypes and ``NaT`` in the denominator (:issue:`35529`)
6868
-
6969
-
7070

pandas/core/arrays/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def __floordiv__(self, other):
628628
result = self.asi8 // other.asi8
629629
mask = self._isnan | other._isnan
630630
if mask.any():
631-
result = result.astype(np.int64)
631+
result = result.astype(np.float64)
632632
result[mask] = np.nan
633633
return result
634634

pandas/tests/arithmetic/test_timedelta64.py

+17
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,23 @@ def test_tdarr_div_length_mismatch(self, box_with_array):
17331733
# ------------------------------------------------------------------
17341734
# __floordiv__, __rfloordiv__
17351735

1736+
def test_td64arr_floordiv_td64arr_with_nat(self, box_with_array):
1737+
# GH#35529
1738+
box = box_with_array
1739+
1740+
left = pd.Series([1000, 222330, 30], dtype="timedelta64[ns]")
1741+
right = pd.Series([1000, 222330, None], dtype="timedelta64[ns]")
1742+
1743+
left = tm.box_expected(left, box)
1744+
right = tm.box_expected(right, box)
1745+
1746+
expected = np.array([1.0, 1.0, np.nan], dtype=np.float64)
1747+
expected = tm.box_expected(expected, box)
1748+
1749+
result = left // right
1750+
1751+
tm.assert_equal(result, expected)
1752+
17361753
def test_td64arr_floordiv_tdscalar(self, box_with_array, scalar_td):
17371754
# GH#18831
17381755
td1 = Series([timedelta(minutes=5, seconds=3)] * 3)

0 commit comments

Comments
 (0)