Skip to content

BUG: .loc assignment of datetime with tz is coercing to naive #11365

Closed
@jreback

Description

@jreback

xref #12502 (example there as well)
xref #14148

In [3]: idx = pd.date_range('20130101',periods=3,tz='US/Eastern')

In [4]: df = DataFrame({'A' : [1,2,3]})

In [5]: df['B'] = idx

In [6]: df.dtypes
Out[6]: 
A                         int64
B    datetime64[ns, US/Eastern]
dtype: object

In [7]: df.loc[[True,False,True],'C'] = idx

In [8]: df
Out[8]: 
   A                         B                   C
0  1 2013-01-01 00:00:00-05:00 2013-01-01 05:00:00
1  2 2013-01-02 00:00:00-05:00                 NaT
2  3 2013-01-03 00:00:00-05:00 2013-01-02 05:00:00

# C should be the same time zone
In [9]: df.dtypes
Out[9]: 
A                         int64
B    datetime64[ns, US/Eastern]
C                datetime64[ns]
dtype: object

this is also realized to #11351 [4]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions