Skip to content

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

Closed
@mroeschke

Description

@mroeschke

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions