Skip to content

BUG: Timedelta.__floordiv__ - need historical context #18846

@jbrockmendel

Description

@jbrockmendel
>>> 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions