Skip to content
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
6 changes: 3 additions & 3 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ def __init__(self, obj, group, squeeze=False, grouper=None, bins=None,
if not index.is_monotonic:
# TODO: sort instead of raising an error
raise ValueError('index must be monotonic for resampling')
s = pd.Series(np.arange(index.size), index)
full_index, first_items = self._get_index_and_items(
index, s, grouper)
index, grouper)
sbins = first_items.values.astype(np.int64)
group_indices = ([slice(i, j)
for i, j in zip(sbins[:-1], sbins[1:])] +
Expand Down Expand Up @@ -307,8 +306,9 @@ def __len__(self):
def __iter__(self):
return zip(self._unique_coord.values, self._iter_grouped())

def _get_index_and_items(self, index, s, grouper):
def _get_index_and_items(self, index, grouper):
from .resample_cftime import CFTimeGrouper
s = pd.Series(np.arange(index.size), index)
if isinstance(grouper, CFTimeGrouper):
first_items = grouper.first_items(index)
full_index = first_items.index
Expand Down
69 changes: 0 additions & 69 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from textwrap import dedent

from textwrap import dedent

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -191,73 +189,6 @@ def test_attribute_repr(self):
assert '\n' not in newlines
assert '\t' not in tabs

def test_diff_array_repr(self):
da_a = xr.DataArray(
np.array([[1, 2, 3], [4, 5, 6]], dtype='int64'),
dims=('x', 'y'),
coords={'x': np.array(['a', 'b'], dtype='U1'),
'y': np.array([1, 2, 3], dtype='int64')},
attrs={'units': 'm', 'description': 'desc'})

da_b = xr.DataArray(
np.array([1, 2], dtype='int64'),
dims='x',
coords={'x': np.array(['a', 'c'], dtype='U1'),
'label': ('x', np.array([1, 2], dtype='int64'))},
attrs={'units': 'kg'})

expected = dedent("""\
Left and right DataArray objects are not identical
Differing dimensions:
(x: 2, y: 3) != (x: 2)
Differing values:
L
array([[1, 2, 3],
[4, 5, 6]], dtype=int64)
R
array([1, 2], dtype=int64)
Differing coordinates:
L * x (x) <U1 'a' 'b'
R * x (x) <U1 'a' 'c'
Coordinates only on the left object:
* y (y) int64 1 2 3
Coordinates only on the right object:
label (x) int64 1 2
Differing attributes:
L units: m
R units: kg
Attributes only on the left object:
description: desc""")

actual = formatting.diff_array_repr(da_a, da_b, 'identical')
try:
assert actual == expected
except AssertionError:
# depending on platform, dtype may not be shown in numpy array repr
assert actual == expected.replace(", dtype=int64", "")

va = xr.Variable('x', np.array([1, 2, 3], dtype='int64'),
{'title': 'test Variable'})
vb = xr.Variable(('x', 'y'),
np.array([[1, 2, 3], [4, 5, 6]], dtype='int64'))

expected = dedent("""\
Left and right Variable objects are not equal
Differing dimensions:
(x: 3) != (x: 2, y: 3)
Differing values:
L
array([1, 2, 3], dtype=int64)
R
array([[1, 2, 3],
[4, 5, 6]], dtype=int64)""")

actual = formatting.diff_array_repr(va, vb, 'equals')
try:
assert actual == expected
except AssertionError:
assert actual == expected.replace(", dtype=int64", "")

def test_diff_dataset_repr(self):
ds_a = xr.Dataset(
data_vars={
Expand Down