has2k1 / mizani

A scales package for python
https://mizani.readthedocs.io
BSD 3-Clause "New" or "Revised" License
49 stars 14 forks source link

date_format doesn't respect localized time zone #8

Closed lorin closed 6 years ago

lorin commented 6 years ago

date_format doesn't respect the time zone of a pandas.Timestamp:

>>> from mizani.formatters import date_format
>>> import pandas as pd
>>>
>>> ts_utc = pd.Timestamp('2017-11-30 23:16:00', tz='UTC')
>>> ts_pst = ts_utc.tz_convert('US/Pacific')
>>> ts_pst.strftime("%H")
'15'
>>> date_format("%H")([tc_pst])
['23']
has2k1 commented 6 years ago

Work around

>>> f = date_format("%H")
>>> f.formatter.tz = ts_pst.tz
>>> f([ts_pst])
['15']
has2k1 commented 6 years ago

The issue is, because we use Matplotlib internals the most sane solution would be to use the timezone of the first date. So if you pass the format functions times with different dates the result may be surprising.

lorin commented 6 years ago

Seems reasonable, and it would cover my use case.

If you were concerned about a user submitting different timezones, you could do a check that they are all the same and emit a warning if they aren't.