@@ -394,3 +394,71 @@ def test_write_and_read_dataset_fsspec_roundtrip(memory_fs):
394394 np .testing .assert_array_equal (ds2 .coords ["lat" ].values , ds .coords ["lat" ].values )
395395 np .testing .assert_array_equal (ds2 .coords ["lon" ].values , ds .coords ["lon" ].values )
396396 assert ds2 .attrs ["description" ] == "full fsspec roundtrip"
397+
398+
399+ # --- open_dataset fsspec tests ---
400+
401+
402+ @filter_numpy_size_warning
403+ def test_open_dataset_fsspec_tuple (memory_fs ):
404+ """open_dataset accepts an (fs, path) tuple to read via fsspec."""
405+ temperature_data = np .random .rand (5 , 5 ).astype (np .float32 )
406+ ds = xr .Dataset (
407+ {"temperature" : (["lat" , "lon" ], temperature_data )},
408+ coords = {
409+ "lat" : np .arange (5 , dtype = np .float32 ),
410+ "lon" : np .arange (5 , dtype = np .float32 ),
411+ },
412+ attrs = {"description" : "tuple test" },
413+ )
414+ path = "tuple_open_test.om"
415+ write_dataset (ds , path , fs = memory_fs , scale_factor = 100000.0 )
416+
417+ ds2 = xr .open_dataset ((memory_fs , path ), engine = "om" )
418+ np .testing .assert_array_almost_equal (ds2 ["temperature" ].values , temperature_data , decimal = 4 )
419+ np .testing .assert_array_equal (ds2 .coords ["lat" ].values , ds .coords ["lat" ].values )
420+ np .testing .assert_array_equal (ds2 .coords ["lon" ].values , ds .coords ["lon" ].values )
421+ assert ds2 .attrs ["description" ] == "tuple test"
422+
423+
424+ @filter_numpy_size_warning
425+ def test_open_dataset_fsspec_tuple_local (local_fs ):
426+ """open_dataset with a local fsspec (fs, path) tuple."""
427+ ds = xr .Dataset (
428+ {"temperature" : (["lat" , "lon" ], np .random .rand (8 , 8 ).astype (np .float32 ))},
429+ coords = {
430+ "lat" : np .arange (8 , dtype = np .float32 ),
431+ "lon" : np .arange (8 , dtype = np .float32 ),
432+ },
433+ )
434+ with tempfile .NamedTemporaryFile (suffix = ".om" , delete = False ) as tmp :
435+ tmp_path = tmp .name
436+ try :
437+ write_dataset (ds , tmp_path , fs = local_fs , scale_factor = 100000.0 )
438+ ds2 = xr .open_dataset ((local_fs , tmp_path ), engine = "om" )
439+ np .testing .assert_array_almost_equal (ds2 ["temperature" ].values , ds ["temperature" ].values , decimal = 4 )
440+ finally :
441+ os .unlink (tmp_path )
442+
443+
444+ @filter_numpy_size_warning
445+ def test_open_dataset_fsspec_full_roundtrip (memory_fs ):
446+ """Full roundtrip: write_dataset with fs=, read back with open_dataset (fs, path) tuple."""
447+ temperature_data = np .random .rand (5 , 5 ).astype (np .float32 )
448+ ds = xr .Dataset (
449+ {"temperature" : (["lat" , "lon" ], temperature_data )},
450+ coords = {
451+ "lat" : np .arange (5 , dtype = np .float32 ),
452+ "lon" : np .arange (5 , dtype = np .float32 ),
453+ },
454+ attrs = {"description" : "full roundtrip" },
455+ )
456+ path = "full_roundtrip_open.om"
457+ write_dataset (ds , path , fs = memory_fs , scale_factor = 100000.0 )
458+
459+ # Read back via (fs, path) tuple — no temp file needed
460+ ds2 = xr .open_dataset ((memory_fs , path ), engine = "om" )
461+ np .testing .assert_array_almost_equal (ds2 ["temperature" ].values , temperature_data , decimal = 4 )
462+ np .testing .assert_array_equal (ds2 .coords ["lat" ].values , ds .coords ["lat" ].values )
463+ np .testing .assert_array_equal (ds2 .coords ["lon" ].values , ds .coords ["lon" ].values )
464+ assert ds2 .attrs ["description" ] == "full roundtrip"
0 commit comments