Skip to content

Commit de81fd7

Browse files
committed
Merge pull request #569 from shoyer/convert-objects-fix
BUG: ensure xray works with pandas 0.17.0
2 parents 3d11031 + 12f8563 commit de81fd7

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ matrix:
3232
- libnetcdf-dev
3333
env: UPDATE_ENV="conda install cython && pip install https://github.com/Unidata/netcdf4-python/archive/master.zip"
3434
- python: 2.7
35-
env: UPDATE_ENV="pip install toolz https://github.com/ContinuumIO/dask/archive/master.zip"
35+
env: UPDATE_ENV="pip install toolz https://github.com/blaze/dask/archive/master.zip"
36+
- python: 2.7
37+
env: UPDATE_ENV="conda remove pandas && conda install cython && pip install https://github.com/pydata/pandas/archive/master.zip"
3638
allow_failures:
3739
- python: 2.7
3840
env: UPDATE_ENV="pip install pydap"
@@ -44,7 +46,9 @@ matrix:
4446
- libnetcdf-dev
4547
env: UPDATE_ENV="conda install cython && pip install https://github.com/Unidata/netcdf4-python/archive/master.zip"
4648
- python: 2.7
47-
env: UPDATE_ENV="pip install toolz https://github.com/ContinuumIO/dask/archive/master.zip"
49+
env: UPDATE_ENV="pip install toolz https://github.com/blaze/dask/archive/master.zip"
50+
- python: 2.7
51+
env: UPDATE_ENV="conda remove pandas && conda install cython && pip install https://github.com/pydata/pandas/archive/master.zip"
4852

4953
before_install:
5054
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Enhancements
3232
Bug fixes
3333
~~~~~~~~~
3434

35+
- Forwards compatibility with the next release of changes (v0.17.0).
36+
We were using some internal pandas routines for datetime conversion, which
37+
unfortunately have now changed upstream (:issue:`569`).
3538
- Aggregation functions now correctly skip ``NaN`` for data for ``complex128``
3639
dtype (:issue:`554`).
3740
- Fixed indexing 0d arrays with unicode dtype (:issue:`568`).

xray/core/common.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,6 @@ def _maybe_promote(dtype):
418418

419419
def _possibly_convert_objects(values):
420420
"""Convert arrays of datetime.datetime and datetime.timedelta objects into
421-
datetime64 and timedelta64
421+
datetime64 and timedelta64, according to the pandas convention.
422422
"""
423-
try:
424-
converter = functools.partial(pd.core.common._possibly_convert_objects,
425-
convert_numeric=False)
426-
except AttributeError:
427-
# our fault for using a private pandas API that has gone missing
428-
# this should do the same coercion (though it will be slower)
429-
converter = lambda x: np.asarray(pd.Series(x))
430-
return converter(values.ravel()).reshape(values.shape)
423+
return np.asarray(pd.Series(values.ravel())).reshape(values.shape)

xray/core/variable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ def _as_compatible_data(data, fastpath=False):
119119
data = np.asarray(data)
120120

121121
if isinstance(data, np.ndarray):
122-
data = common._possibly_convert_objects(data)
123-
if data.dtype.kind == 'M':
124-
# TODO: automatically cast arrays of datetime objects as well
122+
if data.dtype.kind == 'O':
123+
data = common._possibly_convert_objects(data)
124+
elif data.dtype.kind == 'M':
125125
data = np.asarray(data, 'datetime64[ns]')
126-
if data.dtype.kind == 'm':
126+
elif data.dtype.kind == 'm':
127127
data = np.asarray(data, 'timedelta64[ns]')
128128

129129
return _maybe_wrap_data(data)

xray/test/test_dask.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ def test_concat(self):
151151

152152
def test_missing_methods(self):
153153
v = self.lazy_var
154-
with self.assertRaisesRegexp(NotImplementedError, 'dask'):
155-
v.conj()
156-
with self.assertRaisesRegexp(NotImplementedError, 'dask'):
154+
try:
157155
v.argsort()
158-
with self.assertRaisesRegexp(NotImplementedError, 'dask'):
156+
except NotImplementedError as err:
157+
self.assertIn('dask', str(err))
158+
try:
159159
v[0].item()
160+
except NotImplementedError as err:
161+
self.assertIn('dask', str(err))
160162

161163
def test_ufuncs(self):
162164
u = self.eager_var

0 commit comments

Comments
 (0)