Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.ugrid.sel() does not accept dict as input #58

Closed
veenstrajelmer opened this issue Mar 10, 2023 · 3 comments
Closed

.ugrid.sel() does not accept dict as input #58

veenstrajelmer opened this issue Mar 10, 2023 · 3 comments

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Mar 10, 2023

.ugrid.sel() does not accept dictionary as input. Raises "TypeError: Invalid indexer type: dict, allowed types: integer, float, list, numpy array, xarray DataArray". However, using dicts as input for xarray.s ds.sel() is possible.

import xugrid as xu

file_nc = 'c:\\DATA\\dfm_tools_testdata\\DFM_3D_z_Grevelingen\\computations\\run01\\DFM_OUTPUT_Grevelingen-FM\\Grevelingen-FM_0003_map.nc'

uds = xu.open_dataset(file_nc)

#works: passing arguments and values to xugrid's .sel()
uds_sel = uds.ugrid.sel(x=slice(50000,55000),y=slice(None,423000))

#works: passing dict with arguments to xarray's .sel()
uds_sel = uds.sel({'time':slice('2007-11-01','2007-11-05')})

#fails: passing dict with arguments to xugrid's .sel()
uds_sel = uds.ugrid.sel({'x':slice(50000,55000),'y':slice(None,423000)})
@veenstrajelmer
Copy link
Collaborator Author

Workaround is to use ** like this, which unpacks the dictionary:
uds_sel = uds.ugrid.sel(**{'x':slice(50000,55000),'y':slice(None,423000)})

@Huite
Copy link
Collaborator

Huite commented Sep 5, 2024

There's the (copied from xarray) either_dict_or_kwargs function to enable this:

def either_dict_or_kwargs(

@veenstrajelmer
Copy link
Collaborator Author

I do not see why I opened this issue in the first place to be honest. The original code still raises "TypeError: Invalid indexer type: dict, allowed types: integer, float, list, numpy array, xarray DataArray", but the workaround works properly. The function is already not consistent with xarray since x and y are not dimensions, so maybe we can leave this like it is.

@veenstrajelmer veenstrajelmer closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants