Skip to content

use pandas Grouper instead of TimeGrouper #1767

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

Merged
merged 1 commit into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ v0.10.1 (unreleased)
Enhancements
~~~~~~~~~~~~

- :py:func:`~plot.contourf()` learned to contour 2D variables that have both a 1D co-ordinate (e.g. time) and a 2D co-ordinate (e.g. depth as a function of time).
- :py:func:`~plot.contourf()` learned to contour 2D variables that have both a
1D co-ordinate (e.g. time) and a 2D co-ordinate (e.g. depth as a function of
time) (:issue:`1737`).
By `Deepak Cherian <https://github.com/dcherian>`_.
- Use ``pandas.Grouper`` class in xarray resample methods rather than the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is really an enhancement? (not to detract from the honorable work!)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I have a few more small fixes coming so we can bump it down into a miscellaneous fixes category.

deprecated ``pandas.TimeGrouper`` class (:issue:`1766`).
By `Joe Hamman <https://github.com/jhamman>`_.


Bug fixes
Expand Down
11 changes: 5 additions & 6 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@ def resample(self, freq=None, dim=None, how=None, skipna=None,
raise TypeError("Dimension name should be a string; "
"was passed %r" % dim)
group = DataArray(dim, [(dim.dims, dim)], name=RESAMPLE_DIM)
time_grouper = pd.TimeGrouper(freq=freq, closed=closed,
label=label, base=base)
grouper = pd.Grouper(freq=freq, closed=closed, label=label, base=base)
resampler = self._resample_cls(self, group=group, dim=dim_name,
grouper=time_grouper,
grouper=grouper,
resample_dim=RESAMPLE_DIM)

return resampler
Expand All @@ -615,9 +614,9 @@ def _resample_immediately(self, freq, dim, how, skipna,
if isinstance(dim, basestring):
dim = self[dim]
group = DataArray(dim, [(dim.dims, dim)], name=RESAMPLE_DIM)
time_grouper = pd.TimeGrouper(freq=freq, how=how, closed=closed,
label=label, base=base)
gb = self._groupby_cls(self, group, grouper=time_grouper)
grouper = pd.Grouper(freq=freq, how=how, closed=closed, label=label,
base=base)
gb = self._groupby_cls(self, group, grouper=grouper)
if isinstance(how, basestring):
f = getattr(gb, how)
if how in ['first', 'last']:
Expand Down