Repository: ioos/erddapy

Issue:
e.to_xarray falling for new erddapy version
Hi all,

I am developing a jupyternotebook utilizing the erddapy package. My simple code snippet which used to work doesn't seems to work anymore after I reinstall my entire conda environment that run the notebook yesterday. I think it might be related to the erddapy package update.


My code snippet is here 
```
import xarray as xr
from erddapy import ERDDAP

#### access the ERDDAP server
e = ERDDAP(
    server="https://coastwatch.pfeg.noaa.gov/erddap/",    # The URL that the ERDDAP server has
    protocol="griddap",                                   # The data type (griddap or tabledap)
    response="opendap",                                   # different output data type that provided by ERDDAP server       
)

# set the dataset id name 
e.dataset_id = "nceiErsstv4"

# griddap_initialize() help fetch the default variables and constraints available for the data
e.griddap_initialize()

# print available variables and range included in the erddap request
print(e.variables)
print('==========')
print(*e.constraints.items(),sep='\n')

ds = e.to_xarray()
```

The new environment is using the 2.0.1 version. The old working version of erddapy is 1.2.1. After reinstall the erddap to the old version the code above worked as before. Thanks again for creating this useful package!

Discussion:

Patch:
diff --git a/erddapy/erddapy.py b/erddapy/erddapy.py
index d1d0e8e..8ba9d3d 100644
--- a/erddapy/erddapy.py
+++ b/erddapy/erddapy.py
@@ -158,6 +158,10 @@ class ERDDAP:
             )
         if dataset_id is None:
             raise ValueError(f"Must set a valid dataset_id, got {self.dataset_id}")
+        # Return the opendap URL without any slicing so the user can do it later.
+        if self.response == "opendap":
+            return
+
         metadata_url = f"{self.server}/griddap/{self.dataset_id}"
         (
             self.constraints,


Test patch:
diff --git a/tests/test_to_objects.py b/tests/test_to_objects.py
index 0efcbc6..72f5bd9 100644
--- a/tests/test_to_objects.py
+++ b/tests/test_to_objects.py
@@ -155,6 +155,14 @@ def test_to_xarray_opendap(dataset_opendap):
     assert isinstance(ds, xr.Dataset)
 
 
+@pytest.mark.web
+def test_to_xarray_opendap_griddap_initialize(dataset_opendap):
+    """Test converting griddap aftert calling griddap_initialize."""
+    dataset_opendap.griddap_initialize()
+    ds = dataset_opendap.to_xarray()
+    assert isinstance(ds, xr.Dataset)
+
+
 @pytest.mark.web
 @pytest.mark.skipif(
     (sys.platform == "win32" or sys.platform == "darwin"),