Skip to content

BUG(?): Var of Timedelta with empty / NA #18880

Closed
@TomAugspurger

Description

@TomAugspurger

edit: it seems like the bug is that var returns numeric values for the operation, instead of timedeltas like .std (#18880 (comment))


Working on the empty / all-NA stuff. This is related, but separate.

Currently for an all-NA series of timedelta's, we return NaT for .var() on an empty series (see Out[44]). I think this should be NaN since the reduction is returning numeric values, not timedeltas.

In [40]: s = pd.Series(pd.timedelta_range(0, periods=12, freq='S'))

In [41]: s[0] = np.nan

In [42]: s.var()
Out[42]: 1.1e+19

In [43]: s.var(skipna=False)
Out[43]: nan

In [44]: s[:0].var()
Out[44]: NaT

I've just noticed some other buggy behavior with aggregations on timedeltas, so maybe this can become a meta-issue about timedeltas and numeric aggregations:

In [57]: s.sum(skipna=False)
Out[57]: Timedelta('-106752 days +00:13:49.145223')

I'm guessing we improperly add the timedelta min here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Numeric OperationsArithmetic, Comparison, and Logical operationsTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions