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

Fix array compression for non-native byte order #1010

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Update documentation to reflect new 2.8 features. [#998]

- Fix array compression for non-native byte order [#1010]

2.8.1 (2021-06-09)
------------------

Expand Down
2 changes: 1 addition & 1 deletion asdf/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def compress(fd, data, compression, config=None):
data = memoryview(data)
if not data.contiguous:
data = memoryview(data.tobytes()) # make a contiguous copy
data = data.cast('c').cast(data.format) # we get a 1D array by a cast to byte, then a cast to data.format
data = memoryview(np.frombuffer(data, dtype=data.format)) # get a 1D array that preserves byteorder
if not data.contiguous:
# the data will be contiguous by construction, but better safe than sorry!
raise ValueError(data.contiguous)
Expand Down
9 changes: 9 additions & 0 deletions asdf/tests/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def test_set_array_compression(tmpdir):
assert af_in.get_array_compression(af_in.tree['bzp2_data']) == 'bzp2'


def test_nonnative_endian_compression(tmpdir):
ledata = np.arange(1000, dtype='<i8')
bedata = np.arange(1000, dtype='>i8')

_roundtrip(tmpdir,
dict(ledata=ledata, bedata=bedata),
'lz4')


class LzmaCompressor(Compressor):
def compress(self, data, **kwargs):
comp = lzma.compress(data, **kwargs)
Expand Down