Skip to content

BUG: all-NaT TimedeltaArray division with object dtype array doesn't preserve dtype #39750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jorisvandenbossche opened this issue Feb 11, 2021 · 2 comments · Fixed by #44237
Closed
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type
Milestone

Comments

@jorisvandenbossche
Copy link
Member

In [27]: pd.array(["1 days", "2 days"], dtype="timedelta64[ns]") / np.array([2, 2])
Out[27]: 
<TimedeltaArray>
['0 days 12:00:00', '1 days 00:00:00']
Length: 2, dtype: timedelta64[ns]

In [28]: pd.array(["1 days", "2 days"], dtype="timedelta64[ns]") / np.array([2, 2], dtype=object)
Out[28]: 
<TimedeltaArray>
['0 days 12:00:00', '1 days 00:00:00']
Length: 2, dtype: timedelta64[ns]

In [29]: pd.array(["NaT", "NaT"], dtype="timedelta64[ns]") / np.array([2, 2])
Out[29]: 
<TimedeltaArray>
[NaT, NaT]
Length: 2, dtype: timedelta64[ns]

In [30]: pd.array(["NaT", "NaT"], dtype="timedelta64[ns]") / np.array([2, 2], dtype=object)
Out[30]: array([NaT, NaT], dtype=object)

The last case doesn't result in a TimedeltaArray as result.

@jorisvandenbossche jorisvandenbossche added Bug Timedelta Timedelta data type labels Feb 11, 2021
@jorisvandenbossche
Copy link
Member Author

jorisvandenbossche commented Feb 11, 2021

#39753 adds a skip for this in the following test: pandas/tests/arithmetic/test_timedelta64.py::TestTimedeltaArraylikeMulDivOps::test_td64arr_div_numeric_array (so when fixing this bug, that tetst can be updated)

@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Feb 14, 2021
@jorisvandenbossche
Copy link
Member Author

Cases on master using Series/DataFrame:

In [92]: s = pd.Series(["NaT", "NaT"], dtype="timedelta64[ns]")

In [93]: s / np.array([2, 2])
Out[93]: 
0   NaT
1   NaT
dtype: timedelta64[ns]

In [94]: s / np.array([2, 2], dtype=object)
Out[94]: 
0   NaT
1   NaT
dtype: datetime64[ns]   # <---- datetime instead of timedelta

In [95]: df = pd.DataFrame({'a': ["NaT", "NaT"]}, dtype="timedelta64[ns]")

In [96]: (df / np.array([[2], [2]])).dtypes
Out[96]: 
a    timedelta64[ns]
dtype: object

In [97]: (df / np.array([[2], [2]], dtype=object)).dtypes
Out[97]: 
a    object   # <---- object instead of timedelta
dtype: object

@mroeschke mroeschke added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Dtype Conversions Unexpected or buggy dtype conversions labels Aug 15, 2021
@mroeschke mroeschke added this to the 1.4 milestone Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants