7777 has_h5netcdf_1_4_0_or_above ,
7878 has_netCDF4 ,
7979 has_numpy_2 ,
80- has_pydap ,
8180 has_scipy ,
8281 has_zarr ,
8382 has_zarr_v3 ,
@@ -7294,9 +7293,9 @@ def test_netcdf4_entrypoint(tmp_path: Path) -> None:
72947293 _check_guess_can_open_and_open (entrypoint , path , engine = "netcdf4" , expected = ds )
72957294 _check_guess_can_open_and_open (entrypoint , str (path ), engine = "netcdf4" , expected = ds )
72967295
7297- # Remote URLs without extensions are no longer claimed (stricter detection )
7298- assert not entrypoint .guess_can_open ("http://something/remote" )
7299- # Remote URLs with netCDF extensions are claimed
7296+ # Remote URLs without extensions return True (backward compatibility )
7297+ assert entrypoint .guess_can_open ("http://something/remote" )
7298+ # Remote URLs with netCDF extensions are also claimed
73007299 assert entrypoint .guess_can_open ("http://something/remote.nc" )
73017300 assert entrypoint .guess_can_open ("something-local.nc" )
73027301 assert entrypoint .guess_can_open ("something-local.nc4" )
@@ -7440,15 +7439,22 @@ def test_remote_url_backend_auto_detection() -> None:
74407439 f"URL { url !r} should select { expected_backend !r} but got { engine !r} "
74417440 )
74427441
7443- # DAP URLs without extensions - pydap wins if available, netcdf4 otherwise
7444- # When pydap is not installed, netCDF4 should handle these DAP URLs
7445- expected_dap_backend = "pydap" if has_pydap else " netcdf4"
7442+ # DAP URLs - netcdf4 should handle these (it comes first in backend order)
7443+ # Both netcdf4 and pydap can open DAP URLs, but netcdf4 has priority
7444+ expected_dap_backend = "netcdf4"
74467445 dap_urls = [
7446+ # Explicit DAP protocol schemes
74477447 "dap2://opendap.earthdata.nasa.gov/collections/dataset" ,
74487448 "dap4://opendap.earthdata.nasa.gov/collections/dataset" ,
7449+ "dap://example.com/dataset" ,
74497450 "DAP2://example.com/dataset" , # uppercase scheme
74507451 "DAP4://example.com/dataset" , # uppercase scheme
7452+ # DAP path indicators
74517453 "https://example.com/services/DAP2/dataset" , # uppercase in path
7454+ "http://test.opendap.org/opendap/data/nc/file.nc" , # /opendap/ path
7455+ "https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1chla8day" , # ERDDAP
7456+ "http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/" , # THREDDS dodsC
7457+ "https://disc2.gesdisc.eosdis.nasa.gov/dods/TRMM_3B42" , # GrADS /dods/
74527458 ]
74537459
74547460 for url in dap_urls :
@@ -7457,20 +7463,16 @@ def test_remote_url_backend_auto_detection() -> None:
74577463 f"URL { url !r} should select { expected_dap_backend !r} but got { engine !r} "
74587464 )
74597465
7460- # URLs that should raise ValueError (no backend can open them)
7461- invalid_urls = [
7462- "http://test.opendap.org/opendap/data/nc/coads_climatology.nc.dap" , # .dap suffix
7463- "https://example.com/data.dap" , # .dap suffix
7464- "http://opendap.example.com/data" , # no extension, no DAP indicators
7465- "https://test.opendap.org/dataset" , # no extension, no DAP indicators
7466+ # URLs with .dap suffix are claimed by netcdf4 (backward compatibility fallback)
7467+ # Note: .dap suffix is intentionally NOT recognized as a DAP dataset URL
7468+ fallback_urls = [
7469+ ("http://test.opendap.org/opendap/data/nc/coads_climatology.nc.dap" , "netcdf4" ),
7470+ ("https://example.com/data.dap" , "netcdf4" ),
74667471 ]
74677472
7468- for url in invalid_urls :
7469- with pytest .raises (
7470- ValueError ,
7471- match = r"did not find a match in any of xarray's currently installed IO backends" ,
7472- ):
7473- guess_engine (url )
7473+ for url , expected_backend in fallback_urls :
7474+ engine = guess_engine (url )
7475+ assert engine == expected_backend
74747476
74757477
74767478@requires_netCDF4
0 commit comments