Skip to content

Commit

Permalink
BUG: fix to_records confict with unicode_literals pandas-dev#13172
Browse files Browse the repository at this point in the history
  • Loading branch information
starplanet committed May 17, 2016
1 parent 4e4a7d9 commit 62b00d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Bug Fixes


- Bug in ``.groupby(..).resample(..)`` when the same object is called multiple times (:issue:`13174`)
- Bug in ``.to_records()`` when index name is unicode string (:issue: `13172`)


- Regression in ``Series.quantile`` with nans (also shows up in ``.median()`` and ``.describe()``); furthermore now names the ``Series`` with the quantile (:issue:`13098`, :issue:`13146`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def to_records(self, index=True, convert_datetime64=True):
count += 1
elif index_names[0] is None:
index_names = ['index']
names = index_names + lmap(str, self.columns)
names = lmap(str, index_names) + lmap(str, self.columns)
else:
arrays = [self[c].get_values() for c in self.columns]
names = lmap(str, self.columns)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_convert_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,11 @@ def test_to_records_index_name(self):
df.index.names = ['A', None]
rs = df.to_records()
self.assertIn('level_0', rs.dtype.fields)

def test_to_records_with_unicode_index(self):
# GH13172
# unicode_literals conflict with to_records
result = DataFrame([{u'a': u'x', u'b': 'y'}]).set_index(u'a')\
.to_records()
expected = np.rec.array([('x', 'y')], dtype=[('a', 'O'), ('b', 'O')])
tm.assert_numpy_array_equal(result, expected)

0 comments on commit 62b00d3

Please sign in to comment.