diff --git a/CHANGES.md b/CHANGES.md index 97a59efb..902c14c3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +version 1.2.3 (not yet released) +------------- + +Bug Fixes + + - Reading images with empty slices was returning data + version 1.2.2 ------------- diff --git a/fitsio/__init__.py b/fitsio/__init__.py index 956510d0..6cb6eef1 100644 --- a/fitsio/__init__.py +++ b/fitsio/__init__.py @@ -5,7 +5,7 @@ usage. """ -__version__ = '1.2.2' +__version__ = '1.2.3' from . import fitslib diff --git a/fitsio/hdu/image.py b/fitsio/hdu/image.py index a2d16c8d..d8b2965b 100644 --- a/fitsio/hdu/image.py +++ b/fitsio/hdu/image.py @@ -278,8 +278,11 @@ def _read_image_slice(self, arg): step = -1 # Sanity checks for proper syntax. - if (step > 0 and stop < start) or (step < 0 and start < stop): + if ((step > 0 and stop < start) + or (step < 0 and start < stop) + or (start == stop)): return numpy.empty(0, dtype=npy_dtype) + if start < 0: start = dims[dim] + start if start < 0: @@ -293,6 +296,7 @@ def _read_image_slice(self, arg): if stop > dims[dim]: stop = dims[dim] + if stop < start: # A little black magic here. The stop is offset by 2 to # accommodate the 1-offset of CFITSIO, and to move past the end diff --git a/fitsio/tests/test_empty_slice.py b/fitsio/tests/test_empty_slice.py new file mode 100644 index 00000000..a39355bf --- /dev/null +++ b/fitsio/tests/test_empty_slice.py @@ -0,0 +1,21 @@ +import tempfile +import os +import numpy as np +from ..fitslib import write, FITS + + +def test_empty_image_slice(): + + shape = (10, 10) + data = np.arange(shape[0] * shape[1]).reshape(shape) + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.fits') + write(fname, data, clobber=True) + + with FITS(fname) as fits: + assert fits[0][0:0, 0:0].size == 0 + + assert fits[0][0:8, 0:0].size == 0 + + assert fits[0][0:0, 0:8].size == 0 diff --git a/setup.py b/setup.py index e1cce1ba..d6282856 100644 --- a/setup.py +++ b/setup.py @@ -318,7 +318,7 @@ def check_system_cfitsio_objects(self, obj_name): setup( name="fitsio", - version="1.2.2", + version="1.2.3", description=description, long_description=long_description, long_description_content_type='text/markdown; charset=UTF-8; variant=GFM',