Draft
Fix Python 3.12 / NumPy 2.0 / pandas 2.x compatibility and runtime bugs#48
Conversation
Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
- Remove unused numpy.linalg.linalg import (removed in NumPy 2.0) - Replace all ~isinstance() with not isinstance() in _pa.py and _multivariate.py - Fix operator precedence bug in elif (not isinstance(...)) & isinstance(...) - Guard return_annualized against empty Series (ZeroDivisionError) - Guard find_drawdowns against empty Series (IndexError/KeyError) - Initialize all drawdown result keys before loop to handle empty input - Move series_flag conversion outside for loop so it always runs - Guard trade_stats perc_win/perc_in_mkt against zero denominator - Guard dd_length/dd_max against empty drawdown arrays - Fix UnboundLocalError in _get_eia_df_v2 exception handler - Return typed empty DataFrame from _get_eia_df_v2 when all requests fail - Raise clear ValueError in chart_eia_sd/chart_eia_steo when no data Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
Copilot
AI
changed the title
Fix Python 3.12+ compatibility and runtime bugs
Fix Python 3.12 / NumPy 2.0 / pandas 2.x compatibility and runtime bugs
Aug 30, 2026
Copilot created this pull request from a session on behalf of
bbcho
August 30, 2026 18:34
View session
…nal API tests - Fix DatetimeIndex.isin() with string dates (broken in pandas 2.0): use pd.to_datetime() in test_prompt_beta to correctly filter out the 2020-04-20/21 negative oil price events. This was causing prompt_beta to compute incorrect betas (0.55 vs expected 0.97 for CL02). - Add _network_available() helper and @requires_network decorator to test_risktools.py - Mark test_ir_df_us, test_trade_stats, test_get_eia_df, test_chart_eia_sd, test_chart_eia_steo as @requires_network so they are skipped in sandboxed/CI environments without API credentials or internet access Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
Co-authored-by: bbcho <47279398+bbcho@users.noreply.github.com>
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.
Several latent bugs surface on modern dependency versions (Python 3.12, NumPy 2.0, pandas 2.x): deprecated bitwise-NOT on
isinstance, removed private NumPy submodule, unguarded division-by-zero, and bare exception handlers referencing unbound variables._pa.py~isinstance(x, T)→not isinstance(x, T)throughout (bitwise NOT onboolis deprecated; becomesSyntaxErrorin future Python)not A & Bevaluated asnot (A & B)— should be(not A) and Breturn_annualizedagainst empty Series (n=0→ZeroDivisionError)find_drawdownsagainst empty Series input; initialize all result keys before loop; moveseries_flagunwrap outside loop (was skipped bycontinue)_multivariate.py~isinstance()→not isinstance()fix insimulate_gbm_MV_main_functions.py_get_eia_df_v2bareexceptusedprint(r.text)whereris unbound whenrequests.get()itself raises →except Exception as e["date", "value", "table_name", "series_id"]columns)trade_statsperc_win,perc_in_mktagainst zero denominator; guarddd_length/dd_maxagainst empty drawdown arrays_charts.pyKeyError/AttributeErrorinchart_eia_sd/chart_eia_steowith a clearValueErrorwhenget_eia_dfreturns no datapytest/test_risktools.pyfrom numpy.linalg.linalg import eigvals—numpy.linalg.linalgprivate submodule was removed in NumPy 2.0 (import was unused anyway)