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

dask: Deprecate close #504

Merged
merged 8 commits into from
Dec 6, 2022
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
14 changes: 10 additions & 4 deletions cf/abstract/constructlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_DEPRECATION_ERROR,
_DEPRECATION_ERROR_DICT,
_DEPRECATION_ERROR_KWARGS,
_DEPRECATION_ERROR_METHOD,
)
from ..mixin_container import Container

Expand Down Expand Up @@ -244,8 +245,8 @@ def __ne__(self, other):
def close(self):
"""Close all files referenced by each construct in the list.

Note that a closed file will be automatically reopened if its
contents are subsequently required.
Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

:Returns:

Expand All @@ -256,8 +257,13 @@ def close(self):
>>> f.close()

"""
for f in self:
f.close()
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

def count(self, value):
"""Return the number of occurrences of value.
Expand Down
15 changes: 11 additions & 4 deletions cf/constructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cfdm

from .functions import _DEPRECATION_ERROR_METHOD
from .query import Query

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -119,6 +120,9 @@ def _flip(self, axes):
def close(self):
"""Close all files referenced by the metadata constructs.

Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

Note that a closed file will be automatically reopened if its
contents are subsequently required.

Expand All @@ -131,10 +135,13 @@ def close(self):
>>> c.close()

"""
# TODODASKAPI - is this method still needed?

for construct in self.filter_by_data().values():
construct.close()
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

def _filter_by_identity(self, arg, identities, todict, _config):
"""Worker function for `filter_by_identity` and `filter`.
Expand Down
11 changes: 10 additions & 1 deletion cf/coordinatereference.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ def close(self):
"""Close all files referenced by coordinate conversion term
values.

Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

:Returns:

`None`
Expand All @@ -287,7 +290,13 @@ def close(self):
>>> c.close()

"""
pass
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

@classmethod
def default_value(cls, term):
Expand Down
13 changes: 10 additions & 3 deletions cf/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def size(self):
def close(self):
"""Close all files referenced by the domain construct.

Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

Note that a closed file will be automatically reopened if its
contents are subsequently required.

Expand All @@ -139,9 +142,13 @@ def close(self):
>>> d.close()

"""
# TODODASK - is this still needed?

self.constructs.close()
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

@_inplace_enabled(default=False)
def flip(self, axes=None, inplace=False):
Expand Down
14 changes: 10 additions & 4 deletions cf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -4971,6 +4971,9 @@ def map_axes(self, other):
def close(self):
"""Close all files referenced by the field construct.

Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

Note that a closed file will be automatically reopened if its
contents are subsequently required.

Expand All @@ -4983,10 +4986,13 @@ def close(self):
>>> f.close()

"""
super().close()

for construct in self.constructs.filter_by_data(todict=True).values():
construct.close()
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

def iscyclic(self, *identity, **filter_kwargs):
"""Returns True if the specified axis is cyclic.
Expand Down
13 changes: 10 additions & 3 deletions cf/mixin/propertiesdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,9 @@ def clip(self, a_min, a_max, units=None, inplace=False, i=False):
def close(self):
"""Close all files referenced by the construct.

Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

Note that a closed file will be automatically reopened if its
contents are subsequently required.

Expand All @@ -2515,9 +2518,13 @@ def close(self):
>>> f.close()

"""
data = self.get_data(None, _fill_value=False)
if data is not None:
data.close()
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

@classmethod
def concatenate(cls, variables, axis=0, _preserve=True):
Expand Down
19 changes: 10 additions & 9 deletions cf/mixin/propertiesdatabounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,9 @@ def clip(
def close(self):
"""Close all files referenced by the construct.

Deprecated at version TODODASKVER. All files are now
automatically closed when not being accessed.

Note that a closed file will be automatically re-opened if its
contents are subsequently required.

Expand All @@ -1286,15 +1289,13 @@ def close(self):
>> c.close()

"""
super().close()

bounds = self.get_bounds(None)
if bounds is not None:
bounds.close()

interior_ring = self.get_interior_ring(None)
if interior_ring is not None:
interior_ring.close()
_DEPRECATION_ERROR_METHOD(
self,
"close",
"All files are now automatically closed when not being accessed.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

@classmethod
def concatenate(cls, variables, axis=0, _preserve=True):
Expand Down
6 changes: 0 additions & 6 deletions cf/test/test_FieldList.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ def test_FieldList__contains__(self):
self.assertIn(g, f)
self.assertNotIn(34.6, f)

def test_FieldList_close(self):
f = cf.FieldList(self.x)
self.assertIsNone(f.close())

repr(f[0])

def test_FieldList__len__(self):
f = cf.FieldList(self.x)

Expand Down
5 changes: 0 additions & 5 deletions cf/test/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,6 @@ def test_geometry_interior_ring_flatten(self):
for i in (0, 1):
self.assertTrue(f.equals(f.flatten(i), verbose=1))

def test_geometry_interior_ring_close(self):
f = cf.read(self.geometry_interior_ring_file, verbose=0)[0]

self.assertIsNone(f.close())

def test_geometry_interior_ring_files(self):
f = cf.read(self.geometry_interior_ring_file, verbose=0)[0]

Expand Down