pydata / pydata/xarray

Support for globs

Open
#9,151 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Is your feature request related to a problem?

When working with larger datasets or arrays with multiple dimensions, where the variable/dimension names are largely similar but differ only by, e.g., some appendix it would be nice to do operations using globs.

On top of that, often operations on datasets where, e.g., not all variables share some dimensions require additional loops over the variables.

In our code base we often have the construct of a dataset where each variable has unique dimensions that are similar in logic.
E.g. a variable called "lambda_nir" with a dimension "spectral_nir", and many more variables where the "_nir" appendix is replaced with different ones.

Then we often have to loop over variables to call apply_ufunc with the explicit dimension.
Here, it would be nice to also call apply_ufunc(..., input_core_dims=["spectral_*"], ...)

Describe the solution you'd like

e.g. instead of doing
ds[["img_a", "img_b", "img_c"]]
I would like to be able to do
ds["img_*"]

Similarly, I would like to be able to replace
ds.mean(["dim_a", "dim_b", "dim_c"])
by
ds.mean("dim_*")

Describe alternatives you've considered

In some operations you can already pass callables, but this is usually more work and less readable than just passing the list of dimensions.

Additional context

This feature is quite a breaking change, so would probably require a long deprecation phase and warn users when using names with * in them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the current dataset selection, reduction methods such as mean, and apply_ufunc handling described in the issue. Define how glob patterns should behave across these operations, including names containing '*', deprecation warnings, and cases where variables have different dimensions; done means the behavior and migration path are specified and covered consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.