Skip to content
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

MAINT: Deprecations #1243

Merged
merged 8 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# module imports
from . import analyze as ana
from . import ecat, imagestats, mriutils
from . import ecat, imagestats, mriutils, orientations
from . import nifti1 as ni1
from . import spm2analyze as spm2
from . import spm99analyze as spm99
Expand Down
7 changes: 7 additions & 0 deletions nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,3 +796,10 @@ def ulp(val=np.float64(1.0)):
fl2 = info['minexp']
# 'nmant' value does not include implicit first bit
return 2 ** (fl2 - info['nmant'])


# Ported from np.compat
def asstr(s):
if isinstance(s, bytes):
return s.decode('latin1')
return str(s)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

... in other words, unless in each instance that asstr is used we know something is always either bytes or str (in which case, why use this func at all???) then the places asstr is used we'll need to put this conditional in. But maybe that's cleaner... I'm happy either way!

2 changes: 1 addition & 1 deletion nibabel/nicom/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utilities for working with DICOM datasets
"""

from numpy.compat.py3k import asstr
from nibabel.casting import asstr


def find_private_section(dcm_data, group_no, creator):
Expand Down
3 changes: 1 addition & 2 deletions nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

import numpy as np
import numpy.linalg as npl
from numpy.compat.py3k import asstr

from . import analyze # module import
from .arrayproxy import get_obj_dtype
from .batteryrunners import Report
from .casting import have_binary128
from .casting import have_binary128, asstr
from .deprecated import alert_future_error
from .filebasedimages import ImageFileError, SerializableImage
from .optpkg import optional_package
Expand Down
2 changes: 1 addition & 1 deletion nibabel/streamlines/trk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import warnings

import numpy as np
from numpy.compat.py3k import asstr

import nibabel as nib
from nibabel.casting import asstr
from nibabel.openers import Opener
from nibabel.orientations import aff2axcodes, axcodes2ornt
from nibabel.volumeutils import endian_codes, native_code, swapped_code
Expand Down
4 changes: 2 additions & 2 deletions nibabel/tests/test_openers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from unittest import mock

import pytest
from numpy.compat.py3k import asbytes, asstr
from packaging.version import Version

from ..casting import asstr
from ..deprecator import ExpiredDeprecationError
from ..openers import HAVE_INDEXED_GZIP, BZ2File, DeterministicGzipFile, ImageOpener, Opener
from ..optpkg import optional_package
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_iter():
for input, does_t in files_to_test:
with Opener(input, 'wb') as fobj:
for line in lines:
fobj.write(asbytes(line + os.linesep))
fobj.write(bytes(line + os.linesep, 'ascii'))
with Opener(input, 'rb') as fobj:
for back_line, line in zip(fobj, lines):
assert asstr(back_line).rstrip() == line
Expand Down