diff --git a/CHANGES.rst b/CHANGES.rst index 55abb534e..ddba2e124 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,8 @@ - Fix bug causing test collection failures in some environments. [#889] +- Fix bug when decompressing arrays with numpy 1.20. [#901] + 2.7.1 (2020-08-18) ------------------ diff --git a/asdf/commands/tests/test_defragment.py b/asdf/commands/tests/test_defragment.py index cce841c51..e53c54cd1 100644 --- a/asdf/commands/tests/test_defragment.py +++ b/asdf/commands/tests/test_defragment.py @@ -13,7 +13,7 @@ def _test_defragment(tmpdir, codec): - x = np.arange(0, 1000, dtype=np.float) + x = np.arange(0, 1000, dtype=float) tree = { 'science_data': x, diff --git a/asdf/commands/tests/test_exploded.py b/asdf/commands/tests/test_exploded.py index 7d73bd6a9..ad4164f70 100644 --- a/asdf/commands/tests/test_exploded.py +++ b/asdf/commands/tests/test_exploded.py @@ -13,7 +13,7 @@ def test_explode_then_implode(tmpdir): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) tree = { 'science_data': x, diff --git a/asdf/commands/tests/test_to_yaml.py b/asdf/commands/tests/test_to_yaml.py index c57597404..41958265b 100644 --- a/asdf/commands/tests/test_to_yaml.py +++ b/asdf/commands/tests/test_to_yaml.py @@ -13,7 +13,7 @@ def test_to_yaml(tmpdir): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) tree = { 'science_data': x, diff --git a/asdf/compression.py b/asdf/compression.py index 435d55e3e..5b59bd416 100644 --- a/asdf/compression.py +++ b/asdf/compression.py @@ -203,7 +203,11 @@ def decompress(fd, used_size, data_size, compression): raise ValueError("Decompressed data too long") elif i + len(decoded) < data_size: raise ValueError("Decompressed data too short") - buffer[i:i+len(decoded)] = decoded + # Previous versions of numpy permitted assignment of an + # empty bytes object to an empty array range, but starting + # with numpy 1.20 this raises an error. + elif len(decoded) > 0: + buffer[i:i+len(decoded)] = decoded return buffer diff --git a/asdf/fits_embed.py b/asdf/fits_embed.py index b1431cca9..1330c3e3c 100644 --- a/asdf/fits_embed.py +++ b/asdf/fits_embed.py @@ -137,8 +137,8 @@ class AsdfInFits(asdf.AsdfFile): from astropy.io import fits hdulist = fits.HDUList() - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float), name='SCI')) - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float), name='DQ')) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float), name='SCI')) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float), name='DQ')) tree = { 'model': { diff --git a/asdf/tags/core/tests/test_ndarray.py b/asdf/tags/core/tests/test_ndarray.py index d5940af05..2c3e03d21 100644 --- a/asdf/tags/core/tests/test_ndarray.py +++ b/asdf/tags/core/tests/test_ndarray.py @@ -60,7 +60,7 @@ def url_mapping(self): def test_sharing(tmpdir): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) tree = { 'science_data': x, 'subset': x[3:-3], @@ -136,7 +136,7 @@ def test_all_dtypes(tmpdir): def test_dont_load_data(): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) tree = { 'science_data': x, 'subset': x[3:-3], @@ -269,7 +269,7 @@ def check_raw_yaml(content): def test_inline(): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) tree = { 'science_data': x, 'subset': x[3:-3], @@ -301,7 +301,7 @@ def test_inline_bare(): def test_mask_roundtrip(tmpdir): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) m = ma.array(x, mask=x > 5) tree = { 'masked_array': m, @@ -321,7 +321,7 @@ def check_asdf(asdf): helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check_asdf) def test_len_roundtrip(tmpdir): - sequence = np.arange(0, 10, dtype=np.int) + sequence = np.arange(0, 10, dtype=int) tree = { 'sequence': sequence } diff --git a/asdf/tests/__init__.py b/asdf/tests/__init__.py index e12246b41..935debd74 100644 --- a/asdf/tests/__init__.py +++ b/asdf/tests/__init__.py @@ -26,7 +26,7 @@ def from_tree(cls, tree, ctx): def create_small_tree(): - x = np.arange(0, 10, dtype=np.float) + x = np.arange(0, 10, dtype=float) tree = { 'science_data': x, 'subset': x[3:-3], diff --git a/asdf/tests/test_fits_embed.py b/asdf/tests/test_fits_embed.py index f5a0c5ec9..5e03c9a0a 100644 --- a/asdf/tests/test_fits_embed.py +++ b/asdf/tests/test_fits_embed.py @@ -435,9 +435,9 @@ def test_dangling_file_handle(tmpdir): # Create FITS file to use for test hdulist = fits.HDUList() - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float))) - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float))) - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float))) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float))) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float))) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float))) hdulist.writeto(fits_filename) hdulist.close() diff --git a/asdf/tests/test_reference.py b/asdf/tests/test_reference.py index 73661a28d..745cbc955 100644 --- a/asdf/tests/test_reference.py +++ b/asdf/tests/test_reference.py @@ -21,13 +21,13 @@ def test_external_reference(tmpdir): exttree = { 'cool_stuff': { - 'a': np.array([0, 1, 2], np.float), - 'b': np.array([3, 4, 5], np.float) + 'a': np.array([0, 1, 2], float), + 'b': np.array([3, 4, 5], float) }, 'list_of_stuff': [ 'foobar', 42, - np.array([7, 8, 9], np.float) + np.array([7, 8, 9], float) ] } external_path = os.path.join(str(tmpdir), 'external.asdf') @@ -172,7 +172,7 @@ def test_external_reference_invalid_fragment(tmpdir): 'list_of_stuff': [ 'foobar', 42, - np.array([7, 8, 9], np.float) + np.array([7, 8, 9], float) ] } external_path = os.path.join(str(tmpdir), 'external.asdf') @@ -207,8 +207,8 @@ def test_make_reference(tmpdir): # Include some ~ and / in the name to make sure that escaping # is working correctly 'f~o~o/': { - 'a': np.array([0, 1, 2], np.float), - 'b': np.array([3, 4, 5], np.float) + 'a': np.array([0, 1, 2], float), + 'b': np.array([3, 4, 5], float) } } external_path = os.path.join(str(tmpdir), 'external.asdf') diff --git a/docs/asdf/features.rst b/docs/asdf/features.rst index 6ceab8a50..c2edce25b 100644 --- a/docs/asdf/features.rst +++ b/docs/asdf/features.rst @@ -434,8 +434,8 @@ respectively. from astropy.io import fits hdulist = fits.HDUList() - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float), name='SCI')) - hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float), name='DQ')) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float), name='SCI')) + hdulist.append(fits.ImageHDU(np.arange(512, dtype=float), name='DQ')) Next we make a tree structure out of the data in the FITS file. Importantly, we use the *same* array references in the FITS `~astropy.io.fits.HDUList` and