man-group / arctic

High performance datastore for time series and tick data
https://arctic.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
3.06k stars 583 forks source link

tzlocal version 3.0 incompatibility #913

Open r-stiller opened 3 years ago

r-stiller commented 3 years ago

Arctic Version

1.80

Arctic Store

VersionStore

Platform and version

Windows 10 x64 21H1, Intel(R) Xeon(R) CPU E3-1271 v3, 16GB

Description of problem and/or code sample that reproduces the issue

Hello there, i ran into a problem when calling library.list_versions()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-109-bf360df79edb> in <module>()
----> 1 library.list_versions()

C:\ProgramData\Miniconda3\envs\tf\lib\site-packages\arctic\store\version_store.py in list_versions(self, symbol, snapshot, latest_only)
    292                                  'deleted': meta.get('deleted', False) if meta else False,
    293                                  # We return offset-aware datetimes in Local Time.
--> 294                                  'date': ms_to_datetime(datetime_to_ms(version['_id'].generation_time)),
    295                                  'snapshots': [snapshots[s] for s in version.get('parent', []) if s in snapshots]})
    296         return versions

C:\ProgramData\Miniconda3\envs\tf\lib\site-packages\arctic\date\_util.py in ms_to_datetime(ms, tzinfo)
    151 
    152     if tzinfo is None:
--> 153         tzinfo = mktz()
    154 
    155     return datetime.datetime.fromtimestamp(ms * 1e-3, tzinfo)

C:\ProgramData\Miniconda3\envs\tf\lib\site-packages\arctic\date\_mktz.py in mktz(zone)
     31     """
     32     if zone is None:
---> 33         zone = tzlocal.get_localzone().zone
     34     zone = six.u(zone)
     35     tz = dateutil.tz.gettz(zone)

AttributeError: 'backports.zoneinfo.ZoneInfo' object has no attribute 'zone'

After a quick research I noticed that the module tzlocal changed from pytz to zoneinfo (backports.zoneinfo on Python 3.8 or earlier) in version 3.0.

I recommend to either pin the version of tzlocal to <3.0 or do something like

try:
   zone = tzlocal.get_localzone().zone
except AttributeError:
   # The zone attribute is called key in tzlocal >= 3.0
   zone = tzlocal.get_localzone().key
r-stiller commented 3 years ago

tzlocal version 4.0 now uses the pytz_deprecation_shim which restores the behaviour of version 2.0. It also introduces the get_localzone_name() function which only returns the timezone name.