@@ -468,6 +468,49 @@ def test_apply_groupby_add():
468468 add (data_array .groupby ("y" ), data_array .groupby ("x" ))
469469
470470
471+ @pytest .mark .parametrize (
472+ ["obj" , "expected" ],
473+ (
474+ pytest .param (
475+ xr .DataArray (
476+ [0 , 1 ],
477+ coords = {
478+ "x" : ("x" , [- 1 , 1 ], {"a" : 1 , "b" : 2 }),
479+ "u" : ("x" , [2 , 3 ], {"c" : 3 }),
480+ },
481+ dims = "x" ,
482+ attrs = {"d" : 4 , "e" : 5 },
483+ ),
484+ xr .DataArray ([0 , 1 ], coords = {"x" : [- 1 , 1 ], "u" : ("x" , [2 , 3 ])}, dims = "x" ),
485+ id = "DataArray" ,
486+ ),
487+ pytest .param (
488+ xr .Dataset (
489+ {"a" : ("x" , [1 , 2 ], {"a" : 1 , "b" : 2 }), "b" : ("x" , [0 , 1 ], {"c" : 3 })},
490+ coords = {
491+ "x" : ("x" , [- 1 , 1 ], {"d" : 4 , "e" : 5 }),
492+ "u" : ("x" , [2 , 3 ], {"f" : 6 }),
493+ },
494+ ),
495+ xr .Dataset (
496+ {"a" : ("x" , [1 , 2 ]), "b" : ("x" , [0 , 1 ])},
497+ coords = {"x" : [- 1 , 1 ], "u" : ("x" , [2 , 3 ])},
498+ ),
499+ id = "Dataset" ,
500+ ),
501+ ),
502+ )
503+ def test_apply_to_dataset (obj , expected ):
504+ def clear_all_attrs (ds ):
505+ new_ds = ds .copy ()
506+ for var in new_ds .variables .values ():
507+ var .attrs .clear ()
508+ new_ds .attrs .clear ()
509+ return new_ds
510+
511+ assert_identical (expected , xr .apply_to_dataset (clear_all_attrs , obj ))
512+
513+
471514def test_unified_dim_sizes ():
472515 assert unified_dim_sizes ([xr .Variable ((), 0 )]) == {}
473516 assert unified_dim_sizes ([xr .Variable ("x" , [1 ]), xr .Variable ("x" , [1 ])]) == {"x" : 1 }
0 commit comments