Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dateparser fails when using start_date & end_date on Windows #222

Closed
steffen746 opened this issue Nov 13, 2020 · 7 comments · Fixed by #224
Closed

Dateparser fails when using start_date & end_date on Windows #222

steffen746 opened this issue Nov 13, 2020 · 7 comments · Fixed by #224

Comments

@steffen746
Copy link

steffen746 commented Nov 13, 2020

Describe the bug
When providing start_date & end_date to DWDObservationData, the dateparser fails. Initially complaining about missing module tzdata. After installing this, dateparser keeps failing with: 'backports.zoneinfo.ZoneInfo' object has no attribute 'localize'.

To Reproduce

from wetterdienst.dwd.observations import DWDObservationData,

observations = DWDObservationData(
            parameters=parameters,
            station_ids=station_id,
            resolution=DWDObservationResolution.MINUTE_10,
            start_date="2020-01-01",
            end_date="2020-10-01",
            tidy_data=True,
            humanize_column_names=True,
            storage=storage,
        )
   501     ) -> pd.DataFrame:
    502         storage = StorageAdapter(persist=True, folder=dwd_archive.__path__[0])
--> 503         observations = DWDObservationData(
    504             parameters=parameters,
    505             station_ids=station_id,

\wetterdienst\dwd\observations\api.py in __init__(self, station_ids, parameters, resolution, periods, start_date, end_date, storage, tidy_data, humanize_column_names)
    142                 end_date = start_date
    143 
--> 144             self.start_date = Timestamp(dateparser.parse(str(start_date)))
    145             self.end_date = Timestamp(dateparser.parse(str(end_date)))
    146 

\dateparser\conf.py in wrapper(*args, **kwargs)
     83                 "settings can only be either dict or instance of Settings class")
     84 
---> 85         return f(*args, **kwargs)
     86     return wrapper

\dateparser\__init__.py in parse(date_string, date_formats, languages, locales, region, settings)
     51                                 region=region, settings=settings)
     52 
---> 53     data = parser.get_date_data(date_string, date_formats)
     54 
     55     if data:

\dateparser\date.py in get_date_data(self, date_string, date_formats)
    415 
    416         for locale in self._get_applicable_locales(date_string):
--> 417             parsed_date = _DateLocaleParser.parse(
    418                 locale, date_string, date_formats, settings=self._settings)
    419             if parsed_date:

\dateparser\date.py in parse(cls, locale, date_string, date_formats, settings)
    192     def parse(cls, locale, date_string, date_formats=None, settings=None):
    193         instance = cls(locale, date_string, date_formats, settings)
--> 194         return instance._parse()
    195 
    196     def _parse(self):

\dateparser\date.py in _parse(self)
    196     def _parse(self):
    197         for parser_name in self._settings.PARSERS:
--> 198             date_obj = self._parsers[parser_name]()
    199             if self._is_valid_date_obj(date_obj):
    200                 return date_obj

\dateparser\date.py in _try_parser(self)
    220                 if 'DATE_ORDER' not in self._settings._mod_settings:
    221                     self._settings.DATE_ORDER = self.locale.info.get('date_order', _order)
--> 222             date_obj, period = date_parser.parse(
    223                 self._get_translated_date(), settings=self._settings)
    224             self._settings.DATE_ORDER = _order

\dateparser\conf.py in wrapper(*args, **kwargs)
     83                 "settings can only be either dict or instance of Settings class")
     84 
---> 85         return f(*args, **kwargs)
     86     return wrapper

\dateparser\date_parser.py in parse(self, date_string, settings)
     35             if 'local' in _settings_tz:
     36                 stz = get_localzone()
---> 37                 date_obj = stz.localize(date_obj)
     38             else:
     39                 date_obj = localize_timezone(date_obj, settings.TIMEZONE)

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

Desktop:

  • OS: Windows
  • Python-Version: 3.8
  • wetterdienst: 0.10
@amotl
Copy link
Member

amotl commented Nov 13, 2020

Dear Steffen,

thanks for reporting this.

Windows has no zoneinfo database. Can you manually install the pytz module and/or set the TIME_ZONE environment variable like set TIME_ZONE="Europe/London" and check if the program will stop croaking then?

I've just use the information from graphite-project/graphite-web#1019 to outline these suggestions. If that doesn't help, we will have to investigate further.

With kind regards,
Andreas.

@amotl
Copy link
Member

amotl commented Nov 13, 2020

After looking further into this, we found others have been running into the same problem, see scrapinghub/dateparser#791. The reason is that tzlocal switched from pytz to tzinfo.

At scrapinghub/dateparser#791 (comment), @spovich was able to work around this problem by explicitly installing tzlocal==2.1.

From looking at scrapinghub/dateparser#792, we figure this issue might have already been sorted out with dateparser-1.0.0, which has been released on Oct 29, 2020. Thanks a bunch!

@gutzbenj: Can I humbly ask you to bump to dateparser-1.0.0 and put out a wetterdienst-0.10.1 bugfix release?

cc @noviluni, @washeck, @Gallaecio

@amotl amotl changed the title Dateparser failing when trys to localize start_date & end_date Dateparser fails when using start_date & end_date on Windows Nov 13, 2020
@gutzbenj
Copy link
Member

Hey @amotl I'm currently busy and kindly ask you to take over for the version bump and release. Is that okay for you?

@amotl
Copy link
Member

amotl commented Nov 13, 2020

@steffen746: Apart from my suggestions above, can you manually install dateparser==1.0.0 into a fresh environment and check if that already solves the problem for you?

@steffen746
Copy link
Author

steffen746 commented Nov 13, 2020

Hey @amotl thanks for your quick reply. Installing tzlocal==2.1 fixes the problem for me. Manually installing dateparser==1.0.0 seems also to fix it.

@amotl
Copy link
Member

amotl commented Nov 14, 2020

Hi @steffen746,

we just released wetterdienst 0.10.1, which upgrades to dateparser 1.0.0. Can I humbly ask you to check again using this release if everything will be alright?

With kind regards,
Andreas.

@steffen746
Copy link
Author

This works fine, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants