BUG: Timedelta.floordiv - need historical context · Issue #18846 · pandas-dev/pandas (original) (raw)

>>> pd.Timedelta(days=3, hours=4) // np.datetime64('NaT')
-1

Timedelta.__floordiv__ and __rfloordiv__ begin with:

        if hasattr(other, 'dtype'):
            # work with i8
            other = other.astype('m8[ns]').astype('i8')

I think this is a historical artifact from early numpy versions, because in core.ops there is a comment:

            # time delta division -> unit less
            # integer gets converted to timedelta in np < 1.6
            if ((self.is_timedelta_lhs and self.is_timedelta_rhs) and
                    not self.is_integer_rhs and not self.is_integer_lhs and
                    self.name in ('__div__', '__truediv__')):

Before I try to fix Timedelta.__floordiv__ can someone knowledgeable weight in on why all dtypes are being converted to i8?