Repository: stac-utils/xpystac (language: python)

Issue:
bands is read as a dimension without a coordinate
```
import pystac_client
import planetary_computer
from shapely.geometry import Point
import stackstac
import xarray as xr

area_of_interest = Point((-120.963122, 37.025915)) # wright solar farm lon lat
range_old = "2015-01-01/2018-01-01"
range_new = "2020-01-01/2021-01-01"
max_cloud_cover = 15

catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
    modifier=planetary_computer.sign_inplace,
)
search_new = catalog.search(
    collections=["sentinel-2-l2a"], 
    intersects=area_of_interest, 
    datetime=range_new, 
    query={"eo:cloud_cover": {"lt": max_cloud_cover}, 's2:mgrs_tile':{'eq':'10SFF'}}, 
    max_items=4 
)
items_new = search_new.item_collection()
```

using stackstac directly shows alls dimensions are coordinates
```
new_range_xarr = stackstac.stack(items_new, assets=["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"])
new_range_xarr
```

using xpystac, only band is left without a coordinate

```
new_range_xarr = xr.open_dataset(items_new, engine="stac", assets=["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"])
new_range_xarr
```


Discussion / hints:

Fix patch:
diff --git a/xpystac/core.py b/xpystac/core.py
index bcc2808..8f22e2d 100644
--- a/xpystac/core.py
+++ b/xpystac/core.py
@@ -70,7 +70,17 @@ def _(
         return odc_stac.load(items, **{"chunks": {"x": 1024, "y": 1024}, **kwargs})
     elif stacking_library == "stackstac":
         stackstac = _import_optional_dependency("stackstac")
-        return stackstac.stack(obj, **kwargs).to_dataset(dim="band", promote_attrs=True)
+        da = stackstac.stack(obj, **kwargs)
+        bands = {}
+        for band in da.band.values:
+            b = da.sel(band=band)
+            scalar_coords = {k: v.item() for k, v in b.coords.items() if v.shape == ()}
+            b = b.assign_attrs(
+                **{k: v for k, v in scalar_coords.items() if v is not None}
+            )
+            b = b.drop_vars(scalar_coords)
+            bands[band] = b
+        return xarray.Dataset(bands, attrs=da.attrs)
 
 
 @to_xarray.register


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
index 688c04b..e1425ff 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -31,6 +31,7 @@ def test_to_xarray_with_pystac_client_search_passes_kwargs_through(simple_search
 def test_to_xarray_with_different_stacking_library(simple_search, stacking_library):
     ds = to_xarray(simple_search, stacking_library=stacking_library)
     assert isinstance(ds, xr.Dataset)
+    assert "band" not in ds.dims
 
 
 def test_to_xarray_with_drop_variables_raises(simple_search):