@@ -250,13 +250,28 @@ def test_names(self):
250
250
assert np .allclose (cfm .with_name ('original' ).coordinates , coords )
251
251
252
252
cfm .add_coordinates ('shifted' , coords + 1 )
253
- assert cfm .get_names () == [ 'original' , 'shifted' ]
253
+ assert set ( cfm .get_names ()) == { 'original' , 'shifted' }
254
254
shifted = cfm .with_name ('shifted' )
255
255
assert np .allclose (shifted .coordinates , coords + 1 )
256
- assert shifted .get_names () == [ 'original' , 'shifted' ]
256
+ assert set ( shifted .get_names ()) == { 'original' , 'shifted' }
257
257
original = shifted .with_name ('original' )
258
258
assert np .allclose (original .coordinates , coords )
259
259
260
+ # Avoid duplicating objects
261
+ assert original .with_name ('original' ) is original
262
+ # But don't try too hard
263
+ assert original .with_name ('original' ) is not cfm
264
+
265
+ # with_name() preserves the exact coordinate mapping of the source object.
266
+ # Modifications of one are immediately available to all others.
267
+ # This is currently an implementation detail, and the expectation is that
268
+ # a family will be created once and then queried, but this behavior could
269
+ # potentially become confusing or relied upon.
270
+ # Change with care.
271
+ shifted .add_coordinates ('shifted-again' , coords + 2 )
272
+ shift2 = shifted .with_name ('shifted-again' )
273
+ shift3 = cfm .with_name ('shifted-again' )
274
+
260
275
261
276
class H5ArrayProxy :
262
277
def __init__ (self , file_like , dataset_name ):
0 commit comments