8000 Filter upstream warning raised by `np.finfo(np.longdouble)` on WSL1 by joshuacwnewton · Pull Request #1310 · nipy/nibabel · GitHub
[go: up one dir, main page]

Skip to content

Filter upstream warning raised by np.finfo(np.longdouble) on WSL1 #1310

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

Merged
Changes from 1 commit
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
Next Next commit
casting.py: Filter WSL1 + np.longdouble warning
This commit filters the following warning:

> UserWarning: Signature b'\x00\xd0\xcc\xcc\xcc\xcc\xcc\xcc\xfb\xbf\x00\x00\x00\x00\x00\x00' for
> <class 'numpy.longdouble'> does not match any known type: falling back to type probe function.
> This warnings [sic] indicates broken support for the dtype!
>  machar = _get_machar(dtype)

 To ensure that this warning is only filtered on WSL1, we try to detect WSL
 by checking for a WSL-specific string from the uname, which appears to be
 endorsed by WSL devs.
 (microsoft/WSL#4555 (comment))

 I also tried checking the `WSL_INTEROP` and `WSL_DISTRO_NAME` environment
 variables as suggested in the above linked issues, but I preferred reusing
 the `platform` module that was already imported inside `casting.py`.

 There is perhaps a more thorough approach where we collect all raised warnings,
 test the collected warnings, etc. but I didn't want to overcomplicate things.
  • Loading branch information
joshuacwnewton committed Mar 23, 2024
commit f23ca14310724897fb24f8061eeee2dc382cf2cc
12 changes: 10 additions & 2 deletions nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

import warnings
from platform import machine, processor
from platform import machine, processor, uname

import numpy as np

Expand Down Expand Up @@ -274,7 +274,15 @@ def type_info(np_type):
nexp=None,
width=width,
)
info = np.finfo(dt)
# Mitigate warning from WSL1 when checking `np.longdouble` (#1309)
# src for '-Microsoft': https://github.com/microsoft/WSL/issues/4555#issuecomment-536862561
with warnings.catch_warnings():
if uname().release.endswith('-Microsoft'):
warnings.filterwarnings(
action='ignore', category=UserWarning, message='Signature.*numpy.longdouble'
)
info = np.finfo(dt)

# Trust the standard IEEE types
nmant, nexp = info.nmant, info.nexp
ret = dict(
Expand Down
0