Skip to content

BUG: DatetimeArray._from_sequence(arg, dtype='tz') raises TypeError #25440

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
mroeschke opened this issue Feb 25, 2019 · 3 comments
Closed

BUG: DatetimeArray._from_sequence(arg, dtype='tz') raises TypeError #25440

mroeschke opened this issue Feb 25, 2019 · 3 comments

Comments

@mroeschke
Copy link
Member

Discovered in #25308 (comment), is this supposed to work @jbrockmendel, @TomAugspurger?

cc @jreback

In [3]: arg = np.array([np.datetime64('2018-01-01')], dtype=object)

In [4]: pd.arrays.DatetimeArray._from_sequence(arg, dtype='UTC')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in pandas_dtype(dtype)
   2036     try:
-> 2037         npdtype = np.dtype(dtype)
   2038     except Exception:

TypeError: data type "UTC" not understood

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-4-506f2a230c35> in <module>
----> 1 pd.arrays.DatetimeArray._from_sequence(arg, dtype='UTC')

 in _from_sequence(cls, data, dtype, copy, tz, freq, dayfirst, yearfirst, ambiguous, int_as_wall_time)
    374             data, dtype=dtype, copy=copy, tz=tz,
    375             dayfirst=dayfirst, yearfirst=yearfirst,
--> 376             ambiguous=ambiguous, int_as_wall_time=int_as_wall_time)
    377
    378         freq, freq_infer = dtl.validate_inferred_freq(freq, inferred_freq,

 in sequence_to_dt64ns(data, dtype, copy, tz, dayfirst, yearfirst, ambiguous, int_as_wall_time)
   1714     inferred_freq = None
   1715
-> 1716     dtype = _validate_dt64_dtype(dtype)
   1717
   1718     if not hasattr(data, "dtype"):

 in _validate_dt64_dtype(dtype)
   1996     """
   1997     if dtype is not None:
-> 1998         dtype = pandas_dtype(dtype)
   1999         if is_dtype_equal(dtype, np.dtype("M8")):
   2000             # no precision, warn

 in pandas_dtype(dtype)
   2041             raise TypeError("data type not understood")
   2042         raise TypeError("data type '{}' not understood".format(
-> 2043             dtype))
   2044
   2045     # Any invalid dtype (such as pd.Timestamp) should raise an error.

TypeError: data type 'UTC' not understood

In [5]: pd.__version__
Out[5]: '0.25.0.dev0+170.g5bf07a99d.dirty'
@TomAugspurger
Copy link
Contributor

No, I don't think so. 'UTC' isn't a dtype or an alias (and I don't think it should be inferred as one).

@TomAugspurger
Copy link
Contributor

dtype='datetime64[ns, UTC]' would work I think.

@mroeschke
Copy link
Member Author

Gotcha. dtype='datetime64[ns, UTC]' works, and agreed that 'UTC' alone shouldn't work here. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants