Skip to content

Commit

Permalink
Merge pull request NCAS-CMS#708 from davidhassell/fix-del-file-location
Browse files Browse the repository at this point in the history
Fix bug that caused `cf.Field.del_file_location` to fail when updating its metdata constructs
  • Loading branch information
davidhassell authored Jan 17, 2024
2 parents c8bdf2b + a987100 commit 1571226
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
9 changes: 9 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
version 3.17.0
--------------

**2024-??-??**

* Fix bug that caused `cf.Field.del_file_location` to fail when
updating its metdata constructs
(https://github.com/NCAS-CMS/cf-python/issues/707)

version 3.16.0
--------------

Expand Down
2 changes: 1 addition & 1 deletion cf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ def del_file_location(

if constructs:
for c in self.constructs.filter_by_data(todict=True).values():
c.del_file_location(location, inplace=True)
c.del_file_location(location)

return location

Expand Down
22 changes: 22 additions & 0 deletions cf/test/test_Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,28 @@ def test_Field_subspace_ugrid(self):
self.assertTrue(g.aux("X").data.range() < 30)
self.assertTrue(g.aux("Y").data.range() < 50)

def test_Field_file_location(self):
f = cf.example_field(0)

self.assertEqual(f.add_file_location("/data/model/"), "/data/model")

cf.write(f, tmpfile)
f = cf.read(tmpfile)[0]
g = f.copy()
location = os.path.dirname(os.path.abspath(tmpfile))

self.assertEqual(f.file_locations(), set((location,)))
self.assertEqual(f.add_file_location("/data/model/"), "/data/model")
self.assertEqual(f.file_locations(), set((location, "/data/model")))

# Check that we haven't changed 'g'
self.assertEqual(g.file_locations(), set((location,)))

self.assertEqual(f.del_file_location("/data/model/"), "/data/model")
self.assertEqual(f.file_locations(), set((location,)))
f.del_file_location("/invalid")
self.assertEqual(f.file_locations(), set((location,)))


if __name__ == "__main__":
print("Run date:", datetime.datetime.now())
Expand Down
16 changes: 8 additions & 8 deletions docs/source/class/cf.Data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -663,22 +663,22 @@ CFA
:toctree: ../method/
:template: method.rst

~cf.Data.file_locations
~cf.Data.del_file_location
~cf.Data.add_file_location
~cf.Data.cfa_clear_file_substitutions
~cf.Data.cfa_del_aggregated_data
~cf.Data.cfa_del_file_substitution
~cf.Data.cfa_file_substitutions
~cf.Data.cfa_update_file_substitutions
~cf.Data.cfa_del_file_substitution
~cf.Data.cfa_has_file_substitutions
~cf.Data.cfa_del_aggregated_data
~cf.Data.cfa_get_aggregated_data
~cf.Data.cfa_get_term
~cf.Data.cfa_get_write
~cf.Data.cfa_has_aggregated_data
~cf.Data.cfa_has_file_substitutions
~cf.Data.cfa_set_aggregated_data
~cf.Data.cfa_get_term
~cf.Data.cfa_get_write
~cf.Data.cfa_set_term
~cf.Data.cfa_set_write
~cf.Data.cfa_update_file_substitutions
~cf.Data.del_file_location
~cf.Data.file_locations

Element-wise arithmetic, bit and comparison operations
------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/source/class/cf.Field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ CFA
:toctree: ../method/
:template: method.rst

~cf.Field.file_locations
~cf.Field.add_file_location
~cf.Field.del_file_location
~cf.Field.cfa_clear_file_substitutions
~cf.Field.cfa_del_file_substitution
~cf.Field.cfa_file_substitutions
~cf.Field.cfa_update_file_substitutions
~cf.Field.del_file_location
~cf.Field.file_locations

Geometries
^^^^^^^^^^
Expand Down

0 comments on commit 1571226

Please sign in to comment.