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

PytzUsageWarning: The localize method is no longer necessary #1089

Open
Ibo0815 opened this issue Oct 20, 2022 · 5 comments · May be fixed by #1109
Open

PytzUsageWarning: The localize method is no longer necessary #1089

Ibo0815 opened this issue Oct 20, 2022 · 5 comments · May be fixed by #1109

Comments

@Ibo0815
Copy link

Ibo0815 commented Oct 20, 2022

Full Usage warning:
PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html date_obj = stz.localize(date_obj)

Line 35 in date_parser.py

Occurs when parsing this here: "2022-10-03 22:00:00"

Python Version:
3.9.1

@Gallaecio
Copy link
Member

It should be fixed in 1.1.2, released today. Please, see if you can reproduce the issue with 1.1.2.

@Gallaecio
Copy link
Member

#1062 (comment)

@zanieb
Copy link

zanieb commented Dec 5, 2022

👋 I can reproduce this on 1.1.4 with

import dateparser
from datetime import datetime

dateparser.parse(
    "in 3 hours",
    settings={
        "TO_TIMEZONE": "UTC",
        "RELATIVE_BASE": datetime.now(),
    },
)

I'm on Python 3.8

@owocado
Copy link
Contributor

owocado commented Dec 6, 2022

@madkinsz yeah interestingly I can also reproduce it on python 3.11 with dateparser 1.1.4

IMG_20221206_115505

@serhii73 serhii73 linked a pull request Dec 7, 2022 that will close this issue
@serhii73 serhii73 self-assigned this Dec 7, 2022
@PythonTryHard
Copy link

PythonTryHard commented Apr 22, 2023

I did some digging. As of writing, dataparser's dependency tzlocal's latest stable (since dependency is not pinned) is 4.3 which utilises pytz-deprecation-shim.

from tzlocal import get_localzone

def get_local_tz(self):
return get_localzone()

if not now.tzinfo:
if hasattr(self.get_local_tz(), 'localize'):
now = self.get_local_tz().localize(now)

As dateparser eagerly .localize(), this leads to the deprecation warning. This has been addressed upstream in this PR from tzlocal and is included after version 5.0b1. Install and it should be gone, though keep in mind the risk of beta versions.

And since tzlocal would have completed migration away from the deprecation shim by the time v5.0 hit stable, perhaps it's time to consider removing the if hasattr(obj, 'localize'): sections, since tzlocal now returns zoneinfo objects?

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

Successfully merging a pull request may close this issue.

6 participants