Skip to content

Commit 35e3655

Browse files
committed
RF - reverse arg order for arraywriter factory
The order was has_intercept, has_slope, because the default for both was true, and it is more common to not want an intercept, than not want a slope. However, (slope, inter) are elsewhere in that order (for example in the class names and in ``get_slope_inter``). I changed the argument order to fit that convention.
1 parent fedd147 commit 35e3655

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

nibabel/analyze.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ def data_to_fileobj(self, data, fileobj):
528528
try:
529529
arr_writer = make_array_writer(data,
530530
out_dtype,
531-
self.has_data_intercept,
532-
self.has_data_slope)
531+
self.has_data_slope,
532+
self.has_data_intercept)
533533
except WriterError:
534534
msg = sys.exc_info()[1] # python 2 / 3 compatibility
535535
raise HeaderTypeError(msg)
@@ -934,8 +934,8 @@ def to_file_map(self, file_map=None):
934934
out_dtype = self.get_data_dtype()
935935
arr_writer = make_array_writer(data,
936936
out_dtype,
937-
hdr.has_data_intercept,
938-
hdr.has_data_slope)
937+
hdr.has_data_slope,
938+
hdr.has_data_intercept)
939939
hdr_fh, img_fh = self._get_fileholders(file_map)
940940
# Check if hdr and img refer to same file; this can happen with odd
941941
# analyze images but most often this is because it's a single nifti file

nibabel/arraywriters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def get_slope_inter(writer):
534534
return slope, inter
535535

536536

537-
def make_array_writer(data, out_type, has_intercept=True, has_slope=True,
537+
def make_array_writer(data, out_type, has_slope=True, has_intercept=True,
538538
**kwargs):
539539
""" Make array writer instance for array `data` and output type `out_type`
540540
@@ -544,10 +544,10 @@ def make_array_writer(data, out_type, has_intercept=True, has_slope=True,
544544
array for which to create array writer
545545
out_type : dtype-like
546546
input to numpy dtype to specify array writer output type
547-
has_intercept : {True, False}
548-
If True, array write can use intercept to adapt the array to `out_type`
549547
has_slope : {True, False}
550548
If True, array write can use scaling to adapt the array to `out_type`
549+
has_intercept : {True, False}
550+
If True, array write can use intercept to adapt the array to `out_type`
551551
\*\*kwargs : other keyword arguments
552552
to pass to the arraywriter class, if it accepts them.
553553
@@ -562,7 +562,7 @@ def make_array_writer(data, out_type, has_intercept=True, has_slope=True,
562562
>>> aw = make_array_writer(np.arange(10), np.uint8, True, True)
563563
>>> type(aw) == SlopeInterArrayWriter
564564
True
565-
>>> aw = make_array_writer(np.arange(10), np.uint8, False, True)
565+
>>> aw = make_array_writer(np.arange(10), np.uint8, True, False)
566566
>>> type(aw) == SlopeArrayWriter
567567
True
568568
>>> aw = make_array_writer(np.arange(10), np.uint8, False, False)

nibabel/tests/test_arraywriters.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,14 @@ def test_writer_maker():
467467
arr = np.arange(10, dtype=np.float64)
468468
aw = make_array_writer(arr, np.float64)
469469
assert_true(isinstance(aw, SlopeInterArrayWriter))
470-
aw = make_array_writer(arr, np.float64, False)
470+
aw = make_array_writer(arr, np.float64, True, True)
471+
assert_true(isinstance(aw, SlopeInterArrayWriter))
472+
aw = make_array_writer(arr, np.float64, True, False)
471473
assert_true(isinstance(aw, SlopeArrayWriter))
472474
aw = make_array_writer(arr, np.float64, False, False)
473475
assert_true(isinstance(aw, ArrayWriter))
474-
assert_raises(ValueError, make_array_writer, arr, np.float64, True, False)
476+
assert_raises(ValueError, make_array_writer, arr, np.float64, False)
477+
assert_raises(ValueError, make_array_writer, arr, np.float64, False, True)
475478
# Does calc_scale get run by default?
476479
aw = make_array_writer(arr, np.int16, calc_scale=False)
477480
assert_equal((aw.slope, aw.inter), (1, 0))

nibabel/volumeutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def can_cast(in_type, out_type, has_intercept=False, has_slope=False):
424424
data = np.ones((1,), in_type)
425425
from .arraywriters import make_array_writer, WriterError
426426
try:
427-
_ = make_array_writer(data, out_type, has_intercept, has_slope)
427+
_ = make_array_writer(data, out_type, has_slope, has_intercept)
428428
except WriterError:
429429
return False
430430
return True
@@ -778,7 +778,7 @@ def calculate_scale(data, out_dtype, allow_intercept):
778778
return 1.0, 0.0, None, None
779779
from .arraywriters import make_array_writer, WriterError, get_slope_inter
780780
try:
781-
writer = make_array_writer(data, out_dtype, allow_intercept, True)
781+
writer = make_array_writer(data, out_dtype, True, allow_intercept)
782782
except WriterError:
783783
msg = sys.exc_info()[1] # python 2 / 3 compatibility
784784
raise ValueError(msg)

0 commit comments

Comments
 (0)