question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Allow to reset tz from DatetimeIndex holding time representation

See original GitHub issue

There looks no easy way to remove tz from tz-aware DatetimeIndex holding the timestamp represented. What required is inverse operation of tz_localize.

idx = pd.date_range('2014-01-01 09:00', '2014-01-01 20:00', freq='H', tz='Asia/Tokyo')
idx
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 09:00:00+09:00, ..., 2014-01-01 20:00:00+09:00]
# Length: 12, Freq: H, Timezone: Asia/Tokyo

# What I want to do is:
idx.tz_reset()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 09:00:00, ..., 2014-01-01 20:00:00]
# Length: 12, Freq: H, Timezone: None

# This raises TypeError
idx.tz_localize(None)
# TypeError: Already tz-aware, use tz_convert to convert.

# This change the timestamp to UTC
idx.tz_convert(None)
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01 00:00:00, ..., 2014-01-01 11:00:00]
# Length: 12, Freq: H, Timezone: None

In my case, there are some globally distributed data sources which holds local timezones. And want to merge them and analyze based on local subjective times (business hours, etc).

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
sinhrkscommented, Jul 24, 2014

Hmm, both tz_localize and tz_convert “converts” something, the actual behavior should be considered.

  • tz_localize “converts” timezone holding time representation (holding subjective time and change absolute time).
  • tz_convert “converts” timezone holding UTC time (holding absolute time and change subjective time).

The required operation is “holding subjective time and reset timezone”, thus I feel tz_localize(None) is more natural. If we use tz_convert(None) for this operation, tz_convert has inconsistency which sometimes convert subjective time, otherwise convert absolute time.

0reactions
sinhrkscommented, Jul 29, 2014

Thanks, looks more clear. Docs in #7852 uses US timezone and different hours from UTC offset, there should be no problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert pandas timezone-aware DateTimeIndex to naive ...
At display time, the data is offset appropriately and +01:00 (or similar) is added to the string. Stripping off the tz_info value (using...
Read more >
pandas.DatetimeIndex.tz_localize
This method takes a time zone (tz) naive Datetime Array/Index object and makes this time zone aware. It does not move the time...
Read more >
What's New — pandas 0.18.1 documentation - API Manual
API breaking change to the .resample method to make it more .groupby like, ... tz-aware Timestamp and DatetimeIndex now removes timezone holding local...
Read more >
pandas-docs-zh
Easy handling of missing data (represented as NaN) in floating point as well ... .rolling() objects are now time-series aware and can accept...
Read more >
pandas: powerful Python data analysis toolkit - Amazon S3
The default Index printing has changed to a more uniform format, ... for tz-aware Timestamp and DatetimeIndex now removes timezone holding.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found