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

#1178: changes to address datetime.utcnow deprecation warning #1182

Merged
merged 2 commits into from
Aug 24, 2024

Conversation

csessh
Copy link
Contributor

@csessh csessh commented Aug 7, 2024

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

  • 🧪 Added tests for changed code.
  • 🛠️ All tests pass when run locally (run tox or make test to find out!).
  • 🧹 All linting checks pass when run locally (run tox -e lint or make lint to find out!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

Python has raised deprecation warning for the use of datetime.datetime.utcnow(). The suggestion is to use datetime.datetime.now(datetime.UTC) or similar.

This PR addresses just by swapping out all datetime utcnow() calls.
I don't think there's anything in documentation to be updated.

With the example raised in #1178 with humanize():

Python 3.12:

Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> time = arrow.utcnow()
>>> time.humanize()
'just now'
>>> 

No more deprecation warning.

This also works with other python versions, like python 3.11:

Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> time = arrow.utcnow()
>>> time.humanize()
'just now'
>>> time
<Arrow [2024-08-07T02:20:54.376543+00:00]>
>>> 

One thing to note as I setup virtualenv for this:
Despite being listed in requirements.txt, python-dateutil wasn't installed with make build. I had to manually install it.

-> % pip install python-dateutil
Looking in indexes: https://tdo:****@artifactory.sie.sony.com/artifactory/api/pypi/cgei-pypi-release-virtual/simple
Collecting python-dateutil
  Using cached https://artifactory.sie.sony.com/artifactory/api/pypi/cgei-pypi-release-virtual/packages/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
Collecting six>=1.5 (from python-dateutil)
  Using cached https://artifactory.sie.sony.com/artifactory/api/pypi/cgei-pypi-release-virtual/packages/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, python-dateutil
Successfully installed python-dateutil-2.9.0.post0 six-1.16.0

But that's a different thing to this PR.

Closes #1178

@csessh
Copy link
Contributor Author

csessh commented Aug 12, 2024

@jadchaar Please review this PR

Copy link
Member

@jadchaar jadchaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the contribution.

@jadchaar jadchaar merged commit 587af5f into arrow-py:master Aug 24, 2024
18 checks passed
@csessh csessh deleted the python-312-deprecate-utcnow branch August 24, 2024 02:23
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 this pull request may close these issues.

datetime.utcnow is deprecated
2 participants