OSUKED / ElexonDataPortal

Python wrapper for the Elexon/BMRS API
https://osuked.github.io/ElexonDataPortal
MIT License
52 stars 14 forks source link

Cannot compare tz-naive and tz-aware datetime-like objects #25

Open zetinaricky opened 1 year ago

zetinaricky commented 1 year ago

For anyone facing this issue that cannot limit the pandas version here's another fix you could to to avoid the "compare tz-naive and tz-aware datetime-like objects" error is to add the following lines of code in the ElexonDataPortal/dev/utils.py file. to the dt_rng_to_SPs method around line 120 to

    # convert start_date and end_date from tz-naive to tz-aware
    if not isinstance(start_date, str):
        if start_date.tzinfo is None:
            start_date = start_date.tz_localize(tz)

    if not isinstance(end_date, str):
        if end_date.tzinfo is None:
            end_date = end_date.tz_localize(tz)
solmoller commented 10 months ago

Thanks, I have that issue

solmoller commented 10 months ago

Afirm, the added code at the start of the method removes the warning

Incidentally I edited the utils.py I found in /usr/local/lib/python3.9/dist-packages/ElexonDataPortal/dev

I had to ignore this section at the start of the file:

  GNU nano 5.4                                         utils.py                                                   
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01-utils.ipynb (unless otherwise specified).

Thanks!