Skip to content

FIX ignore spurious RuntimeWarning in test on macOS M1 machines #21070

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sklearn/linear_model/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# License: BSD 3 clause

import platform
import pytest

import numpy as np
Expand Down Expand Up @@ -54,6 +55,11 @@ def test_linear_model_normalize_deprecation_message(
model.fit(X, y)
# Filter record in case other unrelated warnings are raised
unwanted = [r for r in record if r.category != warning_category]
if platform.system() == "Darwin" and platform.processor() == "arm":
# On macOS with a Apple Silicon M1 processor, we can get a spurious
# RuntimeWarning when executing this code. Let us just filter those
# warnings out. See: https://github.com/numpy/numpy/issues/18555
unwanted = [r for r in unwanted if r.category != RuntimeWarning]
Copy link
Member

Choose a reason for hiding this comment

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

This test is kind of flaky with warning_category=None since it catches everything, when I think it wants to focus on the deprecation warning. Maybe we can define unwanted depending on warning_category?

if warning_category is None:
    unwanted = [r for r in record if r.category == FutureWarning]
else:
    unwanted = [r for r in record if r.category != warning_category]

I think this fix will end up to be temporary, so I am okay with leaving the PR as is.

if len(unwanted):
msg = "unexpected warnings:\n"
for w in unwanted:
Expand Down