Uh oh!
There was an error while loading. Please reload this page.
[namedarray] split .set_dims() into .expand_dims() and broadcast_to() - #8380
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
.set_dims(), .transpose() and .T to namedarray.set_dims() into .expand_dims() and broadcast_to()Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Illviljan <14371165+Illviljan@users.noreply.github.com>
dcherian
commented
Dec 5, 2023
I have frequently unwrapped to access and compute on the underlying data container, which does indeed care about axis order. |
Illviljan
commented
Dec 5, 2023
Designing an API around not using the class seems odd to me. I agree that once you have retrieved the underlying data you will indeed have to deal with the axis order. But didn't you feel like you were hacking around a problem with xarray? That's what it sounds like to me. This pattern is not realistic since we support any fromnumpyimportarray_apiasnxpimportxarrayasxrfromxarray.namedarrayimport_array_apiasxrpna=xr.namedarray.core.NamedArray(
dims=("a", None, ("c",)), data=nxp.reshape(nxp.arange(4*4*4), (4, 4, 4))
)
na.expand_dims(x=-2)
na.expand_dims(100=-2) # Error, not a valid identifier, str(100).isidentifier() == FalseIs this what you want then? fromnumpyimportarray_apiasnxpimportxarrayasxrfromxarray.namedarrayimport_array_apiasxrpna=xr.namedarray.core.NamedArray(
dims=("a", None, ("c",)), data=nxp.reshape(nxp.arange(4*4*4), (4, 4, 4))
)
na.expand_dims(dim=100, axis=-2) |
i'm revisiting this PR, and i've noticed that there is no clear agreement on the desired API spec for i understand that na.expand_dims(100=-2)
# or na.expand_dims(None=0)won;t work but the following works na.expand_dims(dim={100:-2})
# or na.expand_dims(dim={None=0})should we then remove support for am i missing something? |
thinking more about this, we don't seem to restrict user from assigning hashables like ( In [33]: v=xr.Variable(data=np.zeros(6).reshape(2, 3), dims=[100, None])
In [34]: vOut[34]: <xarray.Variable (100: 2, None: 3)>array([[0., 0., 0.],
[0., 0., 0.]])
In [35]: v.sel(100=1)
CellIn[35], line1v.sel(100=1)
^SyntaxError: expressioncannotcontainassignment, perhapsyoumeant"=="?so, i'm not sure we should drop na.expand_dims(b=2) |
dcherian
commented
Dec 8, 2023
THis is a fairly minor point so lets just go with |
Illviljan
commented
Dec 9, 2023
Yeah, I'm thinking |
for more information, see https://pre-commit.ci
simplified the `expand_dims` method of the NamedArray class by removing support for multiple and keyword arguments for new dimensions. the change updates the method signature to only accept a single dimension name, enhancing clarity and maintainability. this shift focuses on the common use case of adding a single dimension and moves extended functionality to a separate API.
…llowing only the broadcasting of existing ones
andersy005
commented
Jan 28, 2024
@dcherian, when you get a chance, this is ready for another round of review |
* main: (153 commits) Add overloads to get_axis_num (pydata#8547) Fix CI: temporary pin pytest version to 7.4.* (pydata#8682) Bump the actions group with 1 update (pydata#8678) [namedarray] split `.set_dims()` into `.expand_dims()` and `broadcast_to()` (pydata#8380) Add chunk-friendly code path to `encode_cf_datetime` and `encode_cf_timedelta` (pydata#8575) Fix NetCDF4 C version detection (pydata#8675) groupby: Don't set `method` by default on flox>=0.9 (pydata#8657) Fix automatic broadcasting when wrapping array api class (pydata#8669) Fix unstack method when wrapping array api class (pydata#8668) Fix `variables` arg typo in `Dataset.sortby()` docstring (pydata#8670) dt.weekday_name - removal of function (pydata#8664) Add `dev` dependencies to `pyproject.toml` (pydata#8661) CI: Pin scientific-python/upload-nightly-action to release sha (pydata#8662) Update HOW_TO_RELEASE.md by clarifying where RTD build can be found (pydata#8655) ruff: use extend-exclude (pydata#8649) new whats-new section (pydata#8652) xfail another test on windows (pydata#8648) use first element of residual in _nonpolyfit_1d (pydata#8647) whatsnew for v2024.01.1 implement `isnull` using `full_like` instead of `zeros_like` (pydata#7395) ...
this is the initial phase of our plan to split the
.set_dims()method into two distinct methods.expand_dims()and.broadcast_to()as outlined in the design document.expand_dims()broadcast_to().transpose()and.TtoNamedArraywhats-new.rst