Skip to content

Commit

Permalink
Merge pull request #385 from davidhassell/dask-uncompress
Browse files Browse the repository at this point in the history
dask: `Data.uncompress`
  • Loading branch information
davidhassell authored Apr 20, 2022
2 parents 402245d + f28039c commit 2fc1595
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
46 changes: 16 additions & 30 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,8 @@ def persist(self, inplace=False):
**Examples**
TODODASK
"""
d = _inplace_enabled_define_and_cleanup(self)

Expand Down Expand Up @@ -8254,28 +8256,24 @@ def second(self):
"""
return YMDhms(self, "second")

@daskified(_DASKIFIED_VERBOSE)
@_inplace_enabled(default=False)
def uncompress(self, inplace=False):
"""Uncompress the underlying data.
Compression saves space by identifying and removing unwanted
missing data. Such compression techniques store the data more
efficiently and result in no precision loss.
"""Uncompress the data.
Whether or not the data is compressed does not alter its
functionality nor external appearance.
Only affects data that is compressed by convention, i.e.
Data that is already uncompressed will be returned uncompressed.
* Ragged arrays for discrete sampling geometries (DSG) and
simple geometry cell definitions.
The following type of compression are available:
* Compression by gathering.
* Ragged arrays for discrete sampling geometries (DSG). Three
different types of ragged array representation are
supported.
* Compression by coordinate subsampling.
..
* Compression by gathering.
Data that is already uncompressed is returned
unchanged. Whether the data is compressed or not does not
alter its functionality nor external appearance, but may
affect how the data are written to a dataset on disk.
.. versionadded:: 3.0.6
Expand All @@ -8288,7 +8286,7 @@ def uncompress(self, inplace=False):
:Returns:
`Data` or `None`
The uncompressed data, or `None` of the operation was
The uncompressed data, or `None` if the operation was
in-place.
**Examples**
Expand All @@ -8301,20 +8299,8 @@ def uncompress(self, inplace=False):
"""
d = _inplace_enabled_define_and_cleanup(self)

if not d.get_compression_type():
if inplace:
d = None
return d

config = d.partition_configuration(readonly=False)

for partition in d.partitions.matrix.flat:
partition.open(config)
_ = partition.array
partition.close()

d._del_Array(None)
if d.get_compression_type():
d._del_Array(None)

return d

Expand Down
14 changes: 14 additions & 0 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,20 @@ def test_Data_tolist(self):
self.assertEqual(e, np.array(x).tolist())
self.assertTrue(d.equals(cf.Data(e)))

def test_Data_uncompress(self):
import cfdm

f = cfdm.read("DSG_timeSeries_contiguous.nc")[0]
a = f.data.array
d = cf.Data(cf.RaggedContiguousArray(source=f.data.source()))

self.assertTrue(d.get_compression_type())
self.assertTrue((d.array == a).all())

self.assertIsNone(d.uncompress(inplace=True))
self.assertFalse(d.get_compression_type())
self.assertTrue((d.array == a).all())

def test_Data_data(self):
for d in [
cf.Data(1),
Expand Down

0 comments on commit 2fc1595

Please sign in to comment.