Skip to content

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

Closed
@jreback

Description

@jreback
Contributor

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]

Activity

added this to the 0.17.1 milestone on Oct 18, 2015
taeold

taeold commented on Oct 19, 2015

@taeold
Contributor

@jreback took a stab at the bug outlined above. However, I'm not sure what exactly is meant by

this is also realized to #11351 [4]

The fix I've proposed here doesn't address the referenced bug (AttributeError: 'numpy.ndarray' object has no attribute 'tz_localize'). Is this sufficient fix for this issue or are you looking for a more general fix?

jreback

jreback commented on Oct 19, 2015

@jreback
ContributorAuthor

@taeold yes that is fine. These are independent, just linking them really.

modified the milestones: Next Major Release, 0.17.1 on Nov 15, 2015
modified the milestones: 0.18.1, Next Major Release on Mar 1, 2016
modified the milestones: 0.18.1, 0.18.2 on Apr 25, 2016
modified the milestones: Next Major Release, 0.19.0 on Aug 21, 2016
modified the milestones: Next Major Release, 0.24.0 on Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Relationships

    None yet

      Participants

      @jreback@jorisvandenbossche@taeold

      Issue actions

        BUG: .loc assignment of datetime with tz is coercing to naive · Issue #11365 · pandas-dev/pandas