Skip to content

Commit 210607f

Browse files
cpcloudwesm
authored andcommitted
Add tests
1 parent 40910cb commit 210607f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python/pyarrow/tests/test_convert_pandas.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ def test_multiindex_columns_with_dtypes(self):
156156
df = pd.DataFrame([(1, 'a'), (2, 'b'), (3, 'c')], columns=columns)
157157
_check_pandas_roundtrip(df, preserve_index=True)
158158

159+
def test_multiindex_columns_unicode(self):
160+
columns = pd.MultiIndex.from_arrays([[u'あ', u'い'], ['X', 'Y']])
161+
df = pd.DataFrame([(1, 'a'), (2, 'b'), (3, 'c')], columns=columns)
162+
_check_pandas_roundtrip(df, preserve_index=True)
163+
159164
def test_integer_index_column(self):
160165
df = pd.DataFrame([(1, 'a'), (2, 'b'), (3, 'c')])
161166
_check_pandas_roundtrip(df, preserve_index=True)
@@ -524,6 +529,26 @@ def test_unicode_with_unicode_column_and_index(self):
524529

525530
_check_pandas_roundtrip(df, preserve_index=True)
526531

532+
def test_mixed_unicode_column_names(self):
533+
df = pd.DataFrame({u'あ': [u'い'], 'a': 1}, index=[u'う'])
534+
535+
# TODO(phillipc): Should this raise?
536+
with pytest.raises(AssertionError):
537+
_check_pandas_roundtrip(df, preserve_index=True)
538+
539+
def test_binary_column_name(self):
540+
column_data = [u'い']
541+
data = {u'あ'.encode('utf8'): column_data}
542+
df = pd.DataFrame(data)
543+
544+
# we can't use _check_pandas_roundtrip here because our metdata
545+
# is always decoded as utf8: even if binary goes in, utf8 comes out
546+
t = pa.Table.from_pandas(df, preserve_index=True)
547+
df2 = t.to_pandas()
548+
assert df.values[0] == df2.values[0]
549+
assert df.index.values[0] == df2.index.values[0]
550+
assert df.columns[0] == df2.columns[0].encode('utf8')
551+
527552
def test_bytes_to_binary(self):
528553
values = [u('qux'), b'foo', None, 'bar', 'qux', np.nan]
529554
df = pd.DataFrame({'strings': values})

0 commit comments

Comments
 (0)