@@ -1441,7 +1441,10 @@ def test_autoclose_future_warning(self):
1441
1441
with self .open (tmp_file , autoclose = True ) as actual :
1442
1442
assert_identical (data , actual )
1443
1443
1444
- def test_already_open_dataset (self ):
1444
+
1445
+ @requires_netCDF4
1446
+ class TestNetCDF4AlreadyOpen :
1447
+ def test_base_case (self ):
1445
1448
with create_tmp_file () as tmp_file :
1446
1449
with nc4 .Dataset (tmp_file , mode = "w" ) as nc :
1447
1450
v = nc .createVariable ("x" , "int" )
@@ -1453,7 +1456,7 @@ def test_already_open_dataset(self):
1453
1456
expected = Dataset ({"x" : ((), 42 )})
1454
1457
assert_identical (expected , ds )
1455
1458
1456
- def test_already_open_dataset_group (self ):
1459
+ def test_group (self ):
1457
1460
with create_tmp_file () as tmp_file :
1458
1461
with nc4 .Dataset (tmp_file , mode = "w" ) as nc :
1459
1462
group = nc .createGroup ("g" )
@@ -1476,6 +1479,21 @@ def test_already_open_dataset_group(self):
1476
1479
with pytest .raises (ValueError , match = "must supply a root" ):
1477
1480
backends .NetCDF4DataStore (nc .groups ["g" ], group = "g" )
1478
1481
1482
+ def test_deepcopy (self ):
1483
+ # regression test for https://github.com/pydata/xarray/issues/4425
1484
+ with create_tmp_file () as tmp_file :
1485
+ with nc4 .Dataset (tmp_file , mode = "w" ) as nc :
1486
+ nc .createDimension ("x" , 10 )
1487
+ v = nc .createVariable ("y" , np .int32 , ("x" ,))
1488
+ v [:] = np .arange (10 )
1489
+
1490
+ h5 = nc4 .Dataset (tmp_file , mode = "r" )
1491
+ store = backends .NetCDF4DataStore (h5 )
1492
+ with open_dataset (store ) as ds :
1493
+ copied = ds .copy (deep = True )
1494
+ expected = Dataset ({"y" : ("x" , np .arange (10 ))})
1495
+ assert_identical (expected , copied )
1496
+
1479
1497
1480
1498
@requires_netCDF4
1481
1499
@requires_dask
@@ -2422,7 +2440,10 @@ def test_dump_encodings_h5py(self):
2422
2440
assert actual .x .encoding ["compression" ] == "lzf"
2423
2441
assert actual .x .encoding ["compression_opts" ] is None
2424
2442
2425
- def test_already_open_dataset_group (self ):
2443
+
2444
+ @requires_h5netcdf
2445
+ class TestH5NetCDFAlreadyOpen :
2446
+ def test_open_dataset_group (self ):
2426
2447
import h5netcdf
2427
2448
2428
2449
with create_tmp_file () as tmp_file :
@@ -2443,6 +2464,22 @@ def test_already_open_dataset_group(self):
2443
2464
expected = Dataset ({"x" : ((), 42 )})
2444
2465
assert_identical (expected , ds )
2445
2466
2467
+ def test_deepcopy (self ):
2468
+ import h5netcdf
2469
+
2470
+ with create_tmp_file () as tmp_file :
2471
+ with nc4 .Dataset (tmp_file , mode = "w" ) as nc :
2472
+ nc .createDimension ("x" , 10 )
2473
+ v = nc .createVariable ("y" , np .int32 , ("x" ,))
2474
+ v [:] = np .arange (10 )
2475
+
2476
+ h5 = h5netcdf .File (tmp_file , mode = "r" )
2477
+ store = backends .H5NetCDFStore (h5 )
2478
+ with open_dataset (store ) as ds :
2479
+ copied = ds .copy (deep = True )
2480
+ expected = Dataset ({"y" : ("x" , np .arange (10 ))})
2481
+ assert_identical (expected , copied )
2482
+
2446
2483
2447
2484
@requires_h5netcdf
2448
2485
class TestH5NetCDFFileObject (TestH5NetCDFData ):
0 commit comments