Skip to content
forked from pydata/xarray

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix/groupby-reduc…
Browse files Browse the repository at this point in the history
…e-multiple-dims

* upstream/master:
  Test that Dataset and DataArray resampling are identical (pydata#3412)
  Avoid multiplication DeprecationWarning in rasterio backend (pydata#3428)
  Sync with latest version of cftime (v1.0.4) (pydata#3430)
  Add cftime git tip to upstream-dev + temporarily pin cftime (pydata#3431)
  • Loading branch information
dcherian committed Oct 22, 2019
2 parents 57ba667 + 72be873 commit fe0374b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ci/azure/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ steps:
--upgrade \
git+https://github.com/dask/dask \
git+https://github.com/dask/distributed \
git+https://github.com/zarr-developers/zarr
git+https://github.com/zarr-developers/zarr \
git+https://github.com/Unidata/cftime
condition: eq(variables['UPSTREAM_DEV'], 'true')
displayName: Install upstream dev dependencies

Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/py36-min-all-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- cartopy=0.17
- cdms2=3.1
- cfgrib=0.9
- cftime=1.0
- cftime=1.0.3
- coveralls
- dask=1.2
- distributed=1.27
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- cartopy
- cdms2
- cfgrib
- cftime
- cftime=1.0.3.4
- coveralls
- dask
- distributed
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/py37-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- cartopy
# - cdms2 # Not available on Windows
# - cfgrib>=0.9.2 # Causes Python interpreter crash on Windows
- cftime
- cftime=1.0.3.4
- coveralls
- dask
- distributed
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/py37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- cartopy
- cdms2
- cfgrib
- cftime
- cftime=1.0.3.4
- coveralls
- dask
- distributed
Expand Down
6 changes: 6 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Bug fixes
- Fix :py:meth:`xarray.core.groupby.DataArrayGroupBy.reduce` and
:py:meth:`xarray.core.groupby.DatasetGroupBy.reduce` when reducing over multiple dimensions.
(:issue:`3402`). By `Deepak Cherian <https://github.com/dcherian/>`_
- Minimum cftime version is now 1.0.3. By `Deepak Cherian <https://github.com/dcherian>`_.

New Features
~~~~~~~~~~~~
- Added integration tests against `pint <https://pint.readthedocs.io/>`_.
Expand All @@ -51,6 +53,10 @@ Bug fixes
- Fix regression introduced in v0.14.0 that would cause a crash if dask is installed
but cloudpickle isn't (:issue:`3401`) by `Rhys Doyle <https://github.com/rdoyle45>`_

- Sync with cftime by removing `dayofwk=-1` for cftime>=1.0.4.
By `Anderson Banihirwe <https://github.com/andersy005>`_.


Documentation
~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions xarray/backends/rasterio_.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc
if parse:
nx, ny = riods.width, riods.height
# xarray coordinates are pixel centered
x, _ = (np.arange(nx) + 0.5, np.zeros(nx) + 0.5) * riods.transform
_, y = (np.zeros(ny) + 0.5, np.arange(ny) + 0.5) * riods.transform
x, _ = riods.transform * (np.arange(nx) + 0.5, np.zeros(nx) + 0.5)
_, y = riods.transform * (np.zeros(ny) + 0.5, np.arange(ny) + 0.5)
coords["y"] = y
coords["x"] = x
else:
Expand Down
16 changes: 11 additions & 5 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from ..core.pdcompat import count_not_none
from .cftimeindex import CFTimeIndex, _parse_iso8601_with_reso
from .times import format_cftime_datetime
from distutils.version import LooseVersion


def get_date_type(calendar):
Expand Down Expand Up @@ -222,6 +223,8 @@ def _adjust_n_years(other, n, month, reference_day):
def _shift_month(date, months, day_option="start"):
"""Shift the date to a month start or end a given number of months away.
"""
import cftime

delta_year = (date.month + months) // 12
month = (date.month + months) % 12

Expand All @@ -237,11 +240,14 @@ def _shift_month(date, months, day_option="start"):
day = _days_in_month(reference)
else:
raise ValueError(day_option)
# dayofwk=-1 is required to update the dayofwk and dayofyr attributes of
# the returned date object in versions of cftime between 1.0.2 and
# 1.0.3.4. It can be removed for versions of cftime greater than
# 1.0.3.4.
return date.replace(year=year, month=month, day=day, dayofwk=-1)
if LooseVersion(cftime.__version__) < LooseVersion("1.0.4"):
# dayofwk=-1 is required to update the dayofwk and dayofyr attributes of
# the returned date object in versions of cftime between 1.0.2 and
# 1.0.3.4. It can be removed for versions of cftime greater than
# 1.0.3.4.
return date.replace(year=year, month=month, day=day, dayofwk=-1)
else:
return date.replace(year=year, month=month, day=day)


def roll_qtrday(other, n, month, day_option, modby=3):
Expand Down
14 changes: 8 additions & 6 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def parse_iso8601(datetime_string):


def _parse_iso8601_with_reso(date_type, timestr):
import cftime

default = date_type(1, 1, 1)
result = parse_iso8601(timestr)
replace = {}
Expand All @@ -107,12 +109,12 @@ def _parse_iso8601_with_reso(date_type, timestr):
# TODO: Consider adding support for sub-second resolution?
replace[attr] = int(value)
resolution = attr

# dayofwk=-1 is required to update the dayofwk and dayofyr attributes of
# the returned date object in versions of cftime between 1.0.2 and
# 1.0.3.4. It can be removed for versions of cftime greater than
# 1.0.3.4.
replace["dayofwk"] = -1
if LooseVersion(cftime.__version__) < LooseVersion("1.0.4"):
# dayofwk=-1 is required to update the dayofwk and dayofyr attributes of
# the returned date object in versions of cftime between 1.0.2 and
# 1.0.3.4. It can be removed for versions of cftime greater than
# 1.0.3.4.
replace["dayofwk"] = -1
return default.replace(**replace), resolution


Expand Down
13 changes: 13 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3593,6 +3593,19 @@ def test_resample_old_api(self):
with raises_regex(TypeError, r"resample\(\) no longer supports"):
ds.resample("1D", dim="time")

def test_resample_ds_da_are_the_same(self):
time = pd.date_range("2000-01-01", freq="6H", periods=365 * 4)
ds = xr.Dataset(
{
"foo": (("time", "x"), np.random.randn(365 * 4, 5)),
"time": time,
"x": np.arange(5),
}
)
assert_identical(
ds.resample(time="M").mean()["foo"], ds.foo.resample(time="M").mean()
)

def test_ds_resample_apply_func_args(self):
def func(arg1, arg2, arg3=0.0):
return arg1.mean("time") + arg2 + arg3
Expand Down

0 comments on commit fe0374b

Please sign in to comment.