Skip to content

Commit c768348

Browse files
coroamax-sixty
authored andcommitted
Fix printing summaries of multiindex coords (#3079)
* Fix plotting summaries of multiindex coords Since merging #2293 summarize_variable displays the first and last few entries, so we have to pass all along. * Add bug fix bullet point to whats-new.rst
1 parent ff5c2ef commit c768348

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Bug fixes
4444
- Resolved deprecation warnings from newer versions of matplotlib and dask.
4545
- Compatibility fixes for the upcoming pandas 0.25 and NumPy 1.17 releases.
4646
By `Stephan Hoyer <https://github.com/shoyer>`_.
47+
- Fix summaries for multiindex coordinates (:issue:`3079`).
48+
By `Jonas Hörsch <https://github.com/coroa>`_.
4749
- Fix HDF5 error that could arise when reading multiple groups from a file at
4850
once (:issue:`2954`).
4951
By `Stephan Hoyer <https://github.com/shoyer>`_.

xarray/core/formatting.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ def _summarize_coord_multiindex(coord, col_width, marker):
235235

236236

237237
def _summarize_coord_levels(coord, col_width, marker='-'):
238-
relevant_coord = coord[:30]
239238
return '\n'.join(
240239
[summarize_variable(lname,
241-
relevant_coord.get_level_variable(lname),
240+
coord.get_level_variable(lname),
242241
col_width, marker=marker)
243242
for lname in coord.level_names])
244243

xarray/tests/test_dataarray.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ def test_repr_multiindex(self):
6464
- level_2 (x) int64 1 2 1 2""")
6565
assert expected == repr(self.mda)
6666

67+
def test_repr_multiindex_long(self):
68+
mindex_long = pd.MultiIndex.from_product(
69+
[['a', 'b', 'c', 'd'], [1, 2, 3, 4, 5, 6, 7, 8]],
70+
names=('level_1', 'level_2'))
71+
mda_long = DataArray(list(range(32)),
72+
coords={'x': mindex_long}, dims='x')
73+
expected = dedent("""\
74+
<xarray.DataArray (x: 32)>
75+
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
76+
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])
77+
Coordinates:
78+
* x (x) MultiIndex
79+
- level_1 (x) object 'a' 'a' 'a' 'a' 'a' 'a' 'a' ... 'd' 'd' 'd' 'd' 'd' 'd'
80+
- level_2 (x) int64 1 2 3 4 5 6 7 8 1 2 3 4 5 6 ... 4 5 6 7 8 1 2 3 4 5 6 7 8""") # noqa: E501
81+
assert expected == repr(mda_long)
82+
6783
def test_properties(self):
6884
assert_equal(self.dv.variable, self.v)
6985
assert_array_equal(self.dv.values, self.v.values)

0 commit comments

Comments
 (0)