Skip to content

Commit f5b25c6

Browse files
committed
Fix for groupby math with virtual coordinates
1 parent f200bb6 commit f5b25c6

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

xray/core/dataset.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -415,21 +415,6 @@ def __getstate__(self):
415415
state['_file_obj'] = None
416416
return state
417417

418-
# @property
419-
# def arrays(self):
420-
# """Dictionary of Variable objects contained in this dataset.
421-
422-
# This is a low-level interface into the contents of a dataset. The
423-
# dictionary is frozen to prevent it from being modified in ways that
424-
# could create an inconsistent dataset (e.g., by setting variables with
425-
# inconsistent dimensions).
426-
427-
# In general, to access and modify dataset contents, you should use
428-
# dictionary methods on the dataset itself instead of the variables
429-
# dictionary.
430-
# """
431-
# return Frozen(self._arrays)
432-
433418
@property
434419
def variables(self):
435420
"""Deprecated; do not use"""
@@ -1436,7 +1421,7 @@ def differs(vname, v):
14361421

14371422
if not isinstance(dim, basestring):
14381423
# add dimension last to ensure that its in the final Dataset
1439-
concatenated[dim_name] = dim
1424+
concatenated.coords[dim_name] = dim
14401425

14411426
return concatenated
14421427

xray/test/test_dataset.py

+9
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,15 @@ def test_groupby_math(self):
883883
with self.assertRaisesRegexp(TypeError, 'only support arithmetic'):
884884
grouped + grouped
885885

886+
def test_groupby_math_virtual(self):
887+
ds = Dataset({'x': ('t', [1, 2, 3])},
888+
{'t': pd.date_range('20100101', periods=3)})
889+
grouped = ds.groupby('t.day')
890+
actual = grouped - grouped.mean()
891+
expected = Dataset({'x': ('t', [0, 0, 0])},
892+
{'t': ds['t'], 't.day': ds['t.day']})
893+
self.assertDatasetIdentical(actual, expected)
894+
886895
def test_concat(self):
887896
data = create_test_data()
888897

0 commit comments

Comments
 (0)