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

DeprecationWarning about datetime.utcfromtimestamp in Python-3.12 #830

Open
2 tasks done
wosc opened this issue May 28, 2024 · 2 comments
Open
2 tasks done

DeprecationWarning about datetime.utcfromtimestamp in Python-3.12 #830

wosc opened this issue May 28, 2024 · 2 comments

Comments

@wosc
Copy link

wosc commented May 28, 2024

  • I am on the latest Pendulum version

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • OS version and name: macOS 14.5, Debian Linux 12

  • Pendulum version: 3.0

Issue

datetime.utcfromtimestamp() is used by pendulum.from_timestamp(), but it is deprecated starting in Python-3.12 (the stdlib docs say to use datetime.fromtimestamp(timestamp, tz=timezone.utc) instead):

$ python3.12 -W all
Python 3.12.3 (main, May 14 2024, 07:34:56) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pendulum
>>> pendulum.from_timestamp(1)
/usr/local/lib/python3.12/site-packages/pendulum/__init__.py:295: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  dt = _datetime.datetime.utcfromtimestamp(timestamp)
DateTime(1970, 1, 1, 0, 0, 1, tzinfo=Timezone('UTC'))
@henviso
Copy link

henviso commented Sep 3, 2024

Hello @edgarrmondragon.

Do you know if there was an answer for how to deal with this?

@edgarrmondragon
Copy link
Contributor

Hello @edgarrmondragon.

Do you know if there was an answer for how to deal with this?

Not a maintainer, but since it's just a warning the simplest way to deal with it is to ignore it either globally1 or in the pytest config2 if you use that.

There seems to be an open PR to address this: #803.

Footnotes

  1. https://docs.python.org/3.12/library/warnings.html#warning-filter

  2. https://docs.pytest.org/en/stable/how-to/capture-warnings.html#controlling-warnings

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

No branches or pull requests

3 participants