Skip to content

Commit 62b00d3

Browse files
committed
BUG: fix to_records confict with unicode_literals #13172
1 parent 4e4a7d9 commit 62b00d3

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.18.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Bug Fixes
120120

121121

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

124125

125126
- 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`)

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def to_records(self, index=True, convert_datetime64=True):
10621062
count += 1
10631063
elif index_names[0] is None:
10641064
index_names = ['index']
1065-
names = index_names + lmap(str, self.columns)
1065+
names = lmap(str, index_names) + lmap(str, self.columns)
10661066
else:
10671067
arrays = [self[c].get_values() for c in self.columns]
10681068
names = lmap(str, self.columns)

pandas/tests/frame/test_convert_to.py

+8
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,11 @@ def test_to_records_index_name(self):
172172
df.index.names = ['A', None]
173173
rs = df.to_records()
174174
self.assertIn('level_0', rs.dtype.fields)
175+
176+
def test_to_records_with_unicode_index(self):
177+
# GH13172
178+
# unicode_literals conflict with to_records
179+
result = DataFrame([{u'a': u'x', u'b': 'y'}]).set_index(u'a')\
180+
.to_records()
181+
expected = np.rec.array([('x', 'y')], dtype=[('a', 'O'), ('b', 'O')])
182+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)