Skip to content

BUG: .date and timezones #11757

Closed
Closed
@jreback

Description

@jreback

from SO

In [1]: s = Series(pd.to_datetime([1396670200, 1405733045, 1448248441],unit='s')).dt.tz_localize('UTC').dt.tz_convert('US/Eastern')

In [2]: s
Out[2]: 
0   2014-04-04 23:56:40-04:00
1   2014-07-18 21:24:05-04:00
2   2015-11-22 22:14:01-05:00
dtype: datetime64[ns, US/Eastern]

These are correct as they are in the local timezone, but we are not propogating the tz here and just returning a naive date (in local zone)

In [3]: s.dt.date
Out[3]: 
0    2014-04-04
1    2014-07-18
2    2015-11-22
dtype: object

In [4]: s.dt.date[0]
Out[4]: datetime.date(2014, 4, 4)

These are converted to UTC, then returning a naive date
These should be local & with a timezone attached

In [5]: s.apply(lambda x: x.date())
Out[5]: 
0    2014-04-05
1    2014-07-19
2    2015-11-23
dtype: object

further, test

s.apply(lambda x: x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTestingpandas testing functions or related to the test suiteTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions