Skip to content

Replace deprecated datetime.utcnow() with datetime.now(timezone.utc)#57

Open
wavebyrd wants to merge 120 commits intocuemacro:masterfrom
wavebyrd:fix-utcnow-deprecation
Open

Replace deprecated datetime.utcnow() with datetime.now(timezone.utc)#57
wavebyrd wants to merge 120 commits intocuemacro:masterfrom
wavebyrd:fix-utcnow-deprecation

Conversation

@wavebyrd
Copy link
Copy Markdown

Fixes #55

Summary

This PR replaces all occurrences of the deprecated datetime.utcnow() with datetime.now(timezone.utc) to ensure compatibility with Python 3.12+ and eliminate DeprecationWarning messages.

Changes

  • Updated findatapy/market/marketdatarequest.py - Fixed default parameter and date_parser method
  • Updated findatapy/timeseries/filter.py - Fixed filter_time_series_by_days method
  • Updated findatapy/market/marketdatagenerator.py - Fixed fetch_single_time_series method
  • Updated findatapy/market/datavendorbbg.py - Fixed get_reference_data method
  • Updated tests/test_fetchmd_crypto.py - Fixed test_huobi function
  • Updated findatapy_examples/arcticdb_example.py - Fixed timestamp recording
  • Updated findatapy_examples/arcticdb_md_example.py - Fixed timestamp recording
  • Updated findatapy_examples/eikondata_example.py - Fixed all datetime calculations
  • Added timezone import from datetime module where needed

Testing

All modifications maintain the same behavior, just using the recommended timezone-aware approach instead of the deprecated naive UTC method.

saeedamen and others added 27 commits November 9, 2024 11:33
* testing df returns in correct format without nulls

* added finish date within range

* first tick -> last in finish date test
Python 3.12+ deprecates datetime.utcnow() in favor of timezone-aware
datetime.now(timezone.utc). This change ensures compatibility with
future Python versions and eliminates DeprecationWarning messages.

Changes:
- Updated all occurrences across library code and examples
- Added timezone import where needed
- Fixed incorrect datetime.datetime.now().utcnow() patterns
@wavebyrd wavebyrd force-pushed the fix-utcnow-deprecation branch from 8da6c05 to 7645ea7 Compare March 13, 2026 21:23
@wavebyrd
Copy link
Copy Markdown
Author

Ping - this fixes the Python 3.12+ deprecation warning for datetime.utcnow(). Ready for review when you have a chance!

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.

Replace datetime.utcnow() with datetime.now(datetime.UTC) to prevent deprecation warnings in Python 3.12+

3 participants