Skip to content

BUG: DatetimeIndex cast to object dtype raises/wrong for tzaware #23491

Closed
@jbrockmendel

Description

@jbrockmendel
dti = pd.date_range('2016-01-01', periods=3, tz='US/Central')

>>> pd.Index(dti, dtype=object)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/pandas/core/indexes/base.py", line 294, in __new__
    dtype=dtype, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pandas/core/indexes/datetimes.py", line 453, in __new__
    raise ValueError("cannot localize from non-UTC data")
ValueError: cannot localize from non-UTC data

>>> np.array(dti, dtype=object)
array([1451628000000000000L, 1451714400000000000L, 1451800800000000000L],
      dtype=object)

I expected these to match pd.Index(list(dti), dtype=object) and np.array(list(dti)), respectively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsDatetimeDatetime data dtypeTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions