From 9e0ad3345ff99ef6275680e71d4daf51b82fc748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Fri, 25 May 2018 18:14:50 +0200 Subject: [PATCH 1/2] reconstruct columns from pandas mixed-integer type --- python/pyarrow/pandas_compat.py | 1 + python/pyarrow/tests/test_convert_pandas.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py index 18d8ed3d356c..f3ae4fbdba5b 100644 --- a/python/pyarrow/pandas_compat.py +++ b/python/pyarrow/pandas_compat.py @@ -648,6 +648,7 @@ def _backwards_compatible_index_name(raw_name, logical_name): 'string': np.str_, 'empty': np.object_, 'mixed': np.object_, + 'mixed-integer': np.object_ } diff --git a/python/pyarrow/tests/test_convert_pandas.py b/python/pyarrow/tests/test_convert_pandas.py index 6bdbcca01c6a..b284730d13fe 100644 --- a/python/pyarrow/tests/test_convert_pandas.py +++ b/python/pyarrow/tests/test_convert_pandas.py @@ -1818,7 +1818,7 @@ class TestConvertMisc(object): (np.object, pa.binary()), (np.object, pa.binary(10)), (np.object, pa.list_(pa.int64())), - ] + ] def test_all_none_objects(self): df = pd.DataFrame({'a': [None, None, None]}) @@ -1985,6 +1985,11 @@ def test_non_natural_stride(self): arr = pa.array(data['y'], type=pa.int16()) assert arr.to_pylist() == [-1, 2] + def test_mixed_integer_columns(self): + df = pd.DataFrame({'foo': [], 123: []}) + expected_df = pd.DataFrame({'foo': [], '123': []}) + _check_pandas_roundtrip(df, expected=expected_df, preserve_index=True) + def _fully_loaded_dataframe_example(): from distutils.version import LooseVersion From 0e6d5330bea3357688ea4bc40944b89bdb2eb10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Sz=C5=B1cs?= Date: Sat, 26 May 2018 14:10:58 +0200 Subject: [PATCH 2/2] maintain column order --- python/pyarrow/tests/test_convert_pandas.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/tests/test_convert_pandas.py b/python/pyarrow/tests/test_convert_pandas.py index b284730d13fe..81f2177d8274 100644 --- a/python/pyarrow/tests/test_convert_pandas.py +++ b/python/pyarrow/tests/test_convert_pandas.py @@ -1986,8 +1986,9 @@ def test_non_natural_stride(self): assert arr.to_pylist() == [-1, 2] def test_mixed_integer_columns(self): - df = pd.DataFrame({'foo': [], 123: []}) - expected_df = pd.DataFrame({'foo': [], '123': []}) + row = [[], []] + df = pd.DataFrame(data=[row], columns=['foo', 123]) + expected_df = pd.DataFrame(data=[row], columns=['foo', '123']) _check_pandas_roundtrip(df, expected=expected_df, preserve_index=True)