Skip to content

Commit e684bcc

Browse files
authored
Merge pull request #794 from effigies/deprecate_get_data
MNT: Deprecate DataobjImage.get_data, schedule for removal in 5.0
2 parents 6515c8a + 1f124ea commit e684bcc

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

nibabel/dataobj_images.py

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def dataobj(self):
5656
def _data(self):
5757
return self._dataobj
5858

59+
@deprecate_with_version('get_data() is deprecated in favor of get_fdata(),'
60+
' which has a more predictable return type. To '
61+
'obtain get_data() behavior going forward, use '
62+
'numpy.asanyarray(img.dataobj).',
63+
'3.0', '5.0')
5964
def get_data(self, caching='fill'):
6065
""" Return image data from image with any necessary scaling applied
6166

nibabel/tests/test_removalschedule.py

+22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
('1.0.0', [('nibabel', 'neverexisted')]),
1515
]
1616

17+
ATTRIBUTE_SCHEDULE = [
18+
('5.0.0', [('nibabel.dataobj_images', 'DataobjImage', 'get_data')]),
19+
# Verify that the test will be quiet if the schedule outlives the modules
20+
('1.0.0', [('nibabel', 'Nifti1Image', 'neverexisted')]),
21+
]
22+
1723

1824
def test_module_removal():
1925
for version, to_remove in MODULE_SCHEDULE:
@@ -32,3 +38,19 @@ def test_object_removal():
3238
except ImportError:
3339
continue
3440
assert_false(hasattr(module, obj), msg="Time to remove %s.%s" % (module_name, obj))
41+
42+
43+
def test_attribute_removal():
44+
for version, to_remove in ATTRIBUTE_SCHEDULE:
45+
if cmp_pkg_version(version) < 1:
46+
for module_name, cls, attr in to_remove:
47+
try:
48+
module = __import__(module_name)
49+
except ImportError:
50+
continue
51+
try:
52+
klass = getattr(module, cls)
53+
except AttributeError:
54+
continue
55+
assert_false(hasattr(klass, attr),
56+
msg="Time to remove %s.%s.%s" % (module_name, cls, attr))

0 commit comments

Comments
 (0)