From f23ca14310724897fb24f8061eeee2dc382cf2cc Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Fri, 22 Mar 2024 17:48:06 -0400 Subject: [PATCH 1/3] `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 > 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. (https://github.com/microsoft/WSL/issues/4555#issuecomment-700315063) 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. --- nibabel/casting.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nibabel/casting.py b/nibabel/casting.py index 09015135f..ec8608957 100644 --- a/nibabel/casting.py +++ b/nibabel/casting.py @@ -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 @@ -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( From 50dd737089d46adc1bd5c0e7f97d137c10cb1166 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Sat, 23 Mar 2024 13:41:02 -0400 Subject: [PATCH 2/3] `casting.py`: Remove `uname` check for WSL1 --- nibabel/casting.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nibabel/casting.py b/nibabel/casting.py index ec8608957..77da57e40 100644 --- a/nibabel/casting.py +++ b/nibabel/casting.py @@ -6,7 +6,7 @@ from __future__ import annotations import warnings -from platform import machine, processor, uname +from platform import machine, processor import numpy as np @@ -275,12 +275,10 @@ def type_info(np_type): width=width, ) # 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' - ) + warnings.filterwarnings( + action='ignore', category=UserWarning, message='Signature.*numpy.longdouble' + ) info = np.finfo(dt) # Trust the standard IEEE types From 2978ee8ee45cf8c935b91a5a2e3268406f8f24f6 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Sat, 23 Mar 2024 18:58:47 -0400 Subject: [PATCH 3/3] `.zenodo.json`: Add Joshua Newton --- .zenodo.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.zenodo.json b/.zenodo.json index a30467ebe..553aba054 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -391,6 +391,11 @@ }, { "name": "freec84" + }, + { + "affiliation": "Polytechnique Montréal, Montréal, CA", + "name": "Newton, Joshua", + "orcid": "0009-0005-6963-3812" } ], "keywords": [