@@ -1742,13 +1742,21 @@ class Timedelta(_Timedelta):
1742
1742
other = Timedelta(other)
1743
1743
if other is NaT:
1744
1744
return np.nan
1745
+ if other._reso != self ._reso:
1746
+ raise ValueError (
1747
+ " division between Timedeltas with mismatched resolutions "
1748
+ " are not supported. Explicitly cast to matching resolutions "
1749
+ " before dividing."
1750
+ )
1745
1751
return self .value / float (other.value)
1746
1752
1747
1753
elif is_integer_object(other) or is_float_object(other):
1748
1754
# integers or floats
1749
- if self ._reso != NPY_FR_ns:
1750
- raise NotImplementedError
1751
- return Timedelta(self .value / other, unit = ' ns' )
1755
+ if util.is_nan(other):
1756
+ return NaT
1757
+ return Timedelta._from_value_and_reso(
1758
+ < int64_t> (self .value / other), self ._reso
1759
+ )
1752
1760
1753
1761
elif is_array(other):
1754
1762
return self .to_timedelta64() / other
@@ -1761,8 +1769,12 @@ class Timedelta(_Timedelta):
1761
1769
other = Timedelta(other)
1762
1770
if other is NaT:
1763
1771
return np.nan
1764
- if self ._reso != NPY_FR_ns:
1765
- raise NotImplementedError
1772
+ if self ._reso != other._reso:
1773
+ raise ValueError (
1774
+ " division between Timedeltas with mismatched resolutions "
1775
+ " are not supported. Explicitly cast to matching resolutions "
1776
+ " before dividing."
1777
+ )
1766
1778
return float (other.value) / self .value
1767
1779
1768
1780
elif is_array(other):
@@ -1781,14 +1793,18 @@ class Timedelta(_Timedelta):
1781
1793
other = Timedelta(other)
1782
1794
if other is NaT:
1783
1795
return np.nan
1784
- if self ._reso != NPY_FR_ns:
1785
- raise NotImplementedError
1796
+ if self ._reso != other._reso:
1797
+ raise ValueError (
1798
+ " floordivision between Timedeltas with mismatched resolutions "
1799
+ " are not supported. Explicitly cast to matching resolutions "
1800
+ " before dividing."
1801
+ )
1786
1802
return self .value // other.value
1787
1803
1788
1804
elif is_integer_object(other) or is_float_object(other):
1789
- if self ._reso ! = NPY_FR_ns :
1790
- raise NotImplementedError
1791
- return Timedelta (self . value // other, unit = ' ns ' )
1805
+ if util.is_nan(other) :
1806
+ return NaT
1807
+ return type (self )._from_value_and_reso( self . value // other, self ._reso )
1792
1808
1793
1809
elif is_array(other):
1794
1810
if other.dtype.kind == ' m' :
@@ -1798,9 +1814,7 @@ class Timedelta(_Timedelta):
1798
1814
return _broadcast_floordiv_td64(self .value, other, _floordiv)
1799
1815
elif other.dtype.kind in [' i' , ' u' , ' f' ]:
1800
1816
if other.ndim == 0 :
1801
- if self ._reso != NPY_FR_ns:
1802
- raise NotImplementedError
1803
- return Timedelta(self .value // other)
1817
+ return self // other.item()
1804
1818
else :
1805
1819
return self .to_timedelta64() // other
1806
1820
@@ -1816,8 +1830,12 @@ class Timedelta(_Timedelta):
1816
1830
other = Timedelta(other)
1817
1831
if other is NaT:
1818
1832
return np.nan
1819
- if self ._reso != NPY_FR_ns:
1820
- raise NotImplementedError
1833
+ if self ._reso != other._reso:
1834
+ raise ValueError (
1835
+ " floordivision between Timedeltas with mismatched resolutions "
1836
+ " are not supported. Explicitly cast to matching resolutions "
1837
+ " before dividing."
1838
+ )
1821
1839
return other.value // self .value
1822
1840
1823
1841
elif is_array(other):
@@ -1914,10 +1932,10 @@ cdef _broadcast_floordiv_td64(
1914
1932
if mask:
1915
1933
return np.nan
1916
1934
1917
- return operation(value, other.astype(' m8[ns]' ).astype(' i8' ))
1935
+ return operation(value, other.astype(' m8[ns]' , copy = False ).astype(' i8' ))
1918
1936
1919
1937
else :
1920
- res = operation(value, other.astype(' m8[ns]' ).astype(' i8' ))
1938
+ res = operation(value, other.astype(' m8[ns]' , copy = False ).astype(' i8' ))
1921
1939
1922
1940
if mask.any():
1923
1941
res = res.astype(' f8' )
0 commit comments