Skip to content

quantile method returns quantile coordinates which can raise issues #2023

Closed
@mlepore49

Description

@mlepore49

I browsed the issues to check whether there was an open issue on this, but didn't find anything.
Apologies if it is a duplicate.

I am an happy user of the new quantile method in xarray. I think though that creating a coordinate that has the same name as the method can raise issues.

While updating my code to switch entirely to xarray and the quantile method, I realized that this could be an issue. In the old code I had some datasets created using np.nanpercentiles, in which I had generated the coordinate and named it "q".
At some point in my code I have to retrieve the list of the q values, I used to do that by extracting the values:

x = ds.q.values

updating it to what would be the coordinate automatically generated by xarray, it should be

x = ds.quantile.values

Problem description

But of course, when trying to call the coordinate "quantile" from the dataset, you get an Attribute Error:

AttributeError: 'function' object has no attribute 'values'

This can be easily solved by accessing the coordinate as:

x = ds['quantile'].values

However, I thought to point out that using the same name for the coordinate and the method can raise this type of issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions