8000 RF: Remove unnecessary call to `asbytes` for `b`-prepended strings · nipy/nibabel@d1235a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1235a6

Browse files
committed
RF: Remove unnecessary call to asbytes for b-prepended strings
Remove unnecessary call to `asbytes` for `b`-prepended strings: strings prepended with `b` are already treated as bytes literals: - `TckFile.MAGIC_NUMBER` is b'mrtrix tracks' - `TrkFile.MAGIC_NUMBER` is b'TRACK' Documentation: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals Fixes: ``` /home/runner/work/nibabel/nibabel/nibabel/streamlines/tests/test_streamlines.py:9: DeprecationWarning: `np.compat`, which was used during the Python 2 to 3 transition, is deprecated since 1.26.0, and will be removed from numpy.compat.py3k import asbytes ``` raised for example at: https://github.com/nipy/nibabel/actions/runs/9637811213/job/26577586721#step:7:178
1 parent d18022d commit d1235a6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

nibabel/streamlines/tests/test_streamlines.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import numpy as np
88
import pytest
9-
from numpy.compat.py3k import asbytes
109

1110
import nibabel as nib
1211
from nibabel.testing import clear_and_catch_warnings, data_path, error_warnings
@@ -95,7 +94,7 @@ def test_is_supported_detect_format(tmp_path):
9594
# Valid file without extension
9695
for tfile_cls in FORMATS.values():
9796
f = BytesIO()
98-
f.write(asbytes(tfile_cls.MAGIC_NUMBER))
97+
f.write(tfile_cls.MAGIC_NUMBER)
9998
f.seek(0, os.SEEK_SET)
10099
assert nib.streamlines.is_supported(f)
101100
assert nib.streamlines.detect_format(f) is tfile_cls
@@ -104,7 +103,7 @@ def test_is_supported_detect_format(tmp_path):
104103
for tfile_cls in FORMATS.values():
105104
fpath = tmp_path / 'test.txt'
106105
with open(fpath, 'w+b') as f:
107-
f.write(asbytes(tfile_cls.MAGIC_NUMBER))
106+
f.write(tfile_cls.MAGIC_NUMBER)
108107
f.seek(0, os.SEEK_SET)
109108
assert nib.streamlines.is_supported(f)
110109
assert nib.streamlines.detect_format(f) is tfile_cls

0 commit comments

Comments
 (0)
0