Repository navigation
REF: Fix pandas 3.1 deprecations (dayofweek, inplace=) - #1427
Open
raohemdutt wants to merge 1 commit into
Open
raohemdutt wants to merge 1 commit into
raohemdutt wants to merge 1 commit into
Conversation
pandas 3.1 emits Pandas4Warning for DatetimeIndex.dayofweek and for inplace= on DataFrame.set_index/drop and Series.sort_index (PDEP-8). With CI's PYTHONWARNINGS set, backtesting/test/__main__.py turns these into errors, which is why the scheduled CI run of 2026-10-01 failed (coverage and deps_prereleases jobs, "FAILED (errors=81)"). - _stats.py: index.dayofweek -> index.day_of_week (pandas >= 1.1) - _util.py: df.set_index(..., inplace=True) -> df = df.set_index(...) - _plotting.py: trades.drop(..., inplace=True) -> reassignment - backtesting.py: heatmap.sort_index(inplace=True) -> reassignment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pandas 3.1 deprecates a few things this package uses, and each one now raises a
Pandas4Warning(aDeprecationWarningsubclass):_stats.py:125index.dayofweek(andindex.weekday)index.day_of_week_util.py:342df.set_index(..., inplace=True)df = df.set_index(...)_plotting.py:183trades.drop(..., inplace=True)trades = trades.drop(...)backtesting.py:1630heatmap.sort_index(inplace=True)heatmap = heatmap.sort_index()Why it matters
CI sets
PYTHONWARNINGS, andbacktesting/test/__main__.pycallswarnings.filterwarnings('error'), so these warnings turn into test errors. The scheduled run on master on 2026-10-01 (run 36806693709) failed in thecoverageanddeps_prereleasesjobs withFAILED (errors=81), all onDatetimeIndex.dayofweek is deprecated. Those jobs had pandas 3.1.0rc0. pandas 3.1.0 is now the normal release thatpip installpicks, so thebuildjobs should start failing the same way.Reproduce
macOS, Python 3.14.3, pandas 3.1.0, numpy 2.5.4, bokeh 3.10.1:
pip install -e '.[test]' TQDM_DISABLE=1 BOKEH_BROWSER=none \ PYTHONWARNINGS=always::FutureWarning,always::DeprecationWarning \ python -m backtesting.testOn master:
FAILED (errors=76, skipped=1).Testing
RuntimeWarningignored: master givesFAILED (errors=74), and this branch givesRan 81 tests ... OK (skipped=1).python -m backtesting.test: 81 tests, OK (skipped=1). ThePandas4Warnings from backtesting.py are gone.flake8 backtesting setup.pypasses.mypygives the same 2factor_cmaperrors as master, which come from bokeh 3.10's type stubs, so this change doesn't add any.day_of_weekwas added in pandas 1.1. bokeh >= 3.1 already requires pandas >= 1.2, so this works with every version the project supports.Notes
DataFrame.reset_indexinplacewarnings, and they come from bokeh's own code (bokeh/models/sources.py:313), not from backtesting.py. That has to be fixed in bokeh.python -m backtesting.testrun locally (withoutPYTHONWARNINGS) does not turn warnings into errors.unittest.main()sets its own'default'filter whensys.warnoptionsis empty, which overrides thefilterwarnings('error')in__main__.py. So these warnings only showed up as failures in CI. A short note about this in CONTRIBUTING.md (or passingwarnings=Falsetounittest.main()so the filters already set in__main__.pystay in effect) would let contributors see the same failures locally. I left that out of this PR to keep it small.馃 Generated with Claude Code