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

forward fill : transpose_coords=False #4167

Closed
NickMortimer opened this issue Jun 22, 2020 · 3 comments
Closed

forward fill : transpose_coords=False #4167

NickMortimer opened this issue Jun 22, 2020 · 3 comments

Comments

@NickMortimer
Copy link

I'm building a DataArray and get the following future warning, but can't seem to find a way to pass
transpose_coords=False to ffill to keep current behavior?

        dsinput['soundspeed'] =(('runname','time','azimuth','depth','range'),(speed1[np.newaxis,np.newaxis,np.newaxis,:,:]))
        dsinput['soundspeed'] =dsinput['soundspeed'].ffill(dim='depth')

/local-home/mor582/miniconda3/envs/dev2/lib/python3.8/site-packages/xarray/core/missing.py:403: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
return apply_ufunc()

@dcherian
Copy link
Contributor

Thanks for filing an issue @NickMortimer .

The transpose call is here and is used because apply_ufunc moves dimensions around so that the "core dimensions" are the last. The explicit transpose then moves the dimensions back to the original order:

def ffill(arr, dim=None, limit=None):
"""forward fill missing values"""
import bottleneck as bn
axis = arr.get_axis_num(dim)
# work around for bottleneck 178
_limit = limit if limit is not None else arr.shape[axis]
return apply_ufunc(
bn.push,
arr,
dask="parallelized",
keep_attrs=True,
output_dtypes=[arr.dtype],
kwargs=dict(n=_limit, axis=axis),
).transpose(*arr.dims)

Now transpose_coords=True is the default in our next release (#3824) so this warning will disappear.

Is there a reason why you want the coordinates to not have the same dimension order as the data? In that case, I would add another transpose call after ffill in your code.

@NickMortimer
Copy link
Author

The warning asked me to set transpose_coords=False to keep the current behavior so my default position is to do that so my code keeps working as is but ffill doesn't take transpose_coords as a parameter or does it in (#3824)?

I'm doing this inside a map_blocks call, and have already established a template and if the dims are swapped on the returned object the process fails as it cannot be combined as it doesn't match the expected template, so yes I added a transpose after the fill, but this does make things more complex as depending on how the user has subset the data the dimensions will change so that will require extra code to get the dimensions before and then to transpose after.

@keewis
Copy link
Collaborator

keewis commented Feb 21, 2021

we had a few releases since then so I assume we can close this. If you disagree, feel free to reopen.

@keewis keewis closed this as completed Feb 21, 2021
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

3 participants