Skip to content

sequence_to_dt64ns doesn't handle non-ndarray sequences with a dtype #24539

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
TomAugspurger opened this issue Jan 1, 2019 · 0 comments · Fixed by #40210
Closed

sequence_to_dt64ns doesn't handle non-ndarray sequences with a dtype #24539

TomAugspurger opened this issue Jan 1, 2019 · 0 comments · Fixed by #40210
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Datetime Datetime data dtype
Milestone

Comments

@TomAugspurger
Copy link
Contributor

For example an xarray.DataArray.

In [21]: import xarray as xr

In [22]: import pandas as pd; import numpy as np

In [23]: arr = xr.DataArray(pd.date_range('2000', periods=4).to_numpy())

In [24]: pd.core.arrays.datetimes.sequence_to_dt64ns(arr)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-24-fd995f4e5bef> in <module>
----> 1 pd.core.arrays.datetimes.sequence_to_dt64ns(arr)

~/sandbox/pandas/pandas/core/arrays/datetimes.py in sequence_to_dt64ns(data, dtype, copy, tz, dayfirst, yearfirst, ambiguous)
   1712         result = result.copy()
   1713
-> 1714     assert isinstance(result, np.ndarray), type(result)
   1715     assert result.dtype == 'M8[ns]', result.dtype
   1716

AssertionError: <class 'xarray.core.dataarray.DataArray'>

A user would hit this via DatetimeIndex(arr)

@TomAugspurger TomAugspurger added the Datetime Datetime data dtype label Jan 1, 2019
@mroeschke mroeschke added the Bug label Apr 1, 2020
@jbrockmendel jbrockmendel added the Constructors Series/DataFrame/Index/pd.array Constructors label Dec 17, 2020
@jreback jreback added this to the 1.3 milestone Mar 16, 2021
bzah added a commit to cerfacs-globc/icclim that referenced this issue May 19, 2022
This pin is needed to avoid this bug: pandas-dev/pandas#24539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants