Skip to content

[FIX] Replace statsmodels.robust.scale.mad with scipy.stats.median_abs_deviation to avoid enabling the GIL - #126

Open
pvlov wants to merge 1 commit into
nbara:masterfrom
pvlov:master
Open

[FIX] Replace statsmodels.robust.scale.mad with scipy.stats.median_abs_deviation to avoid enabling the GIL#126
pvlov wants to merge 1 commit into
nbara:masterfrom
pvlov:master

Conversation

@pvlov

@pvlov pvlov commented Aug 12, 2026

Copy link
Copy Markdown

Hi! Since this is a small diff and I couldn't find a CONTRIBUTING.md, I went ahead and opened a PR. I hope you don't mind!

I wanted to use meegkit in a project that uses a free-threaded Python interpreter, but I ran into the following warning:

<frozen importlib._bootstrap>:491: RuntimeWarning: 
The global interpreter lock (GIL) has been enabled to load module 'statsmodels.robust._qn', 
which has not declared that it can run safely without the GIL. 
To override this behavior and keep the GIL disabled (at your own risk), run with PYTHON_GIL=0 or -Xgil=0.

You can replicate this warning (using uv) with this command:

uv run --no-project --python 3.14t --with statsmodels python -c "import statsmodels.robust.scale"

I checked where/how statsmodels is used and found only one occurrence: statsmodels.robust.scale.mad. This PR replaces it with the equivalent scipy.stats.median_abs_deviation. This makes the package usable in free-threaded contexts while also dropping the statsmodels dependency entirely.

Additionally, I added a test using the built-in sys._is_gil_enabled check to confirm the GIL stays disabled, and added 3.14 and 3.14t to the CI python matrix. Let me know if you want to keep this or if I should drop this.

…s_deviation to avoid enabling the GIL and remove statsmodels from dependencies
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.28%. Comparing base (6b6c1d7) to head (4012864).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #126      +/-   ##
==========================================
- Coverage   83.29%   83.28%   -0.01%     
==========================================
  Files          25       25              
  Lines        2861     2860       -1     
==========================================
- Hits         2383     2382       -1     
  Misses        478      478              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant