Skip to content

Commit

Permalink
BUG: handle unicode level names when formatting MultiIndex close #1736
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Aug 12, 2012
1 parent 4e36441 commit 1dd2c4f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pandas 0.8.2
- Fix bug in scatter_plot with by option (#1716)
- Fix performance problem in infer_freq with lots of non-unique stamps (#1686)
- Fix handling of PeriodIndex as argument to create MultiIndex (#1705)
- Fix re: unicode MultiIndex level names in Series/DataFrame repr (#1736)

pandas 0.8.1
============
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,11 @@ def get_level_values(self, level):
return unique_vals.take(labels)

def format(self, space=2, sparsify=None, adjoin=True, names=False):
from pandas.core.common import _stringify
from pandas.core.format import print_config
def _strify(x):
return _stringify(x, print_config.encoding)

if len(self) == 0:
return []

Expand All @@ -1474,7 +1479,7 @@ def format(self, space=2, sparsify=None, adjoin=True, names=False):
level = []

if names:
level.append(str(name) if name is not None else '')
level.append(_strify(name) if name is not None else '')

level.extend(np.array(lev, dtype=object))
result_levels.append(level)
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,15 @@ def test_unicode_repr_issues(self):
# NumPy bug
# repr(index.get_level_values(1))

def test_unicode_repr_level_names(self):
index = MultiIndex.from_tuples([(0, 0), (1, 1)],
names=[u'\u0394', 'i1'])

s = Series(range(2), index=index)
df = DataFrame(np.random.randn(2,4), index=index)
repr(s)
repr(df)

def test_dataframe_insert_column_all_na(self):
# GH #1534
mix = MultiIndex.from_tuples([('1a', '2a'), ('1a', '2b'), ('1a', '2c')])
Expand Down

0 comments on commit 1dd2c4f

Please sign in to comment.