GithubHelp home page GithubHelp logo

Comments (8)

dcherian avatar dcherian commented on August 23, 2024

The error message mentions: Try passing .groupby(..., squeeze=False) which ends up working. This will be fixed once we finally make that the default. It's been warning for 7 months now.

from xarray.

dcherian avatar dcherian commented on August 23, 2024

Or we can fix the bug here:

# weird backcompat
# reducing along a unique indexed dimension with squeeze=True
# should raise an error
if (dim is None or dim == name) and name in obj.xindexes:
index = obj.indexes[name]
if index.is_unique and self._squeeze:
raise ValueError(f"cannot reduce over dimensions {name!r}")

We need to raise the error for virtual variables too.

from xarray.

max-sixty avatar max-sixty commented on August 23, 2024

OK great!

(so I understand — when we change the default, would da.groupby(dim).mean() work — i.e. with no dim passed to mean? Or we'll still mandate a dim passed to mean? Currently da.groupby('time').mean() fails passes but da.groupby('lat').mean() fails, seemingly because lat is a float index... )

from xarray.

dcherian avatar dcherian commented on August 23, 2024

Turns out it has to do with sortedness of lat. We only check.is_monotonic_increasing but yes if I pass squeeze=False it all works.

def is_unique_and_monotonic(self) -> bool:
if isinstance(self.group, _DummyGroup):
return True
index = self.group_as_index
return index.is_unique and index.is_monotonic_increasing

Could switch it to add is_monotonic_decreasing too.

#6220
#7427

from xarray.

max-sixty avatar max-sixty commented on August 23, 2024

OK great!

So it sounds like after we make that change, it won't be required to pass any dimensions to the aggregation func — da.groupby('lat').mean(), (with nothing passed to mean()), will aggregate over groups along lat without reducing any other dims. (lmk if I'm mistaken)

That'll be much better than the current state, where not passing anything to mean() works depending on the dimension's sortedness + whether flox is installed. Notably, if we only add is_monotonically_decreasing without making squeeze=False the default, it'll still depend on the array sortedness.

TY!

from xarray.

dcherian avatar dcherian commented on August 23, 2024

Setting squeeze=False makes it always work.

#7427 removes the dependence on sortedness. That is, once merged, it will dependably error on main. Perhaps we should just delete the squeeze kwarg, it's been a pain for quite long.

from xarray.

max-sixty avatar max-sixty commented on August 23, 2024

OK v nice — on #7427 this dependably works on both flox & no flox, both ordered & unordered.

with xr.set_options(use_flox=True):
    print(da.assign_coords(lat=lambda x: x.lat % 2).groupby('lat', squeeze=False).sum())

from xarray.

max-sixty avatar max-sixty commented on August 23, 2024

Closed by #9280, thanks !

from xarray.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.