Skip to content

Commit

Permalink
ARROW-1941: [Python] Fix empty list roundtrip in to_pandas
Browse files Browse the repository at this point in the history
This closes [ARROW-1941](https://issues.apache.org/jira/browse/ARROW-1941).

Author: Licht-T <[email protected]>

Closes apache#1449 from Licht-T/fix-empty-list-roundtrip and squashes the following commits:

165dc6f [Licht-T] TST: Add test for the empty list roundtrip
0ddfd87 [Licht-T] BUG: Fix empty list roundtrip
  • Loading branch information
Licht-T authored and wesm committed Jan 2, 2018
1 parent 37c3265 commit 4a3e6e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/src/arrow/python/arrow_to_pandas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct WrapBytes<FixedSizeBinaryArray> {

static inline bool ListTypeSupported(const DataType& type) {
switch (type.id()) {
case Type::NA:
case Type::UINT8:
case Type::INT8:
case Type::UINT16:
Expand Down Expand Up @@ -695,6 +696,7 @@ class ObjectBlock : public PandasBlock {
} else if (type == Type::LIST) {
auto list_type = std::static_pointer_cast<ListType>(col->type());
switch (list_type->value_type()->id()) {
CONVERTLISTSLIKE_CASE(FloatType, NA)
CONVERTLISTSLIKE_CASE(UInt8Type, UINT8)
CONVERTLISTSLIKE_CASE(Int8Type, INT8)
CONVERTLISTSLIKE_CASE(UInt16Type, UINT16)
Expand Down
12 changes: 12 additions & 0 deletions python/pyarrow/tests/test_convert_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,18 @@ def test_table_column_subset_metadata(self):
result = table_subset2.to_pandas()
tm.assert_frame_equal(result, df[['a']].reset_index(drop=True))

def test_empty_list_roundtrip(self):
empty_list_array = np.empty((3,), dtype=object)
empty_list_array.fill([])

df = pd.DataFrame({'a': np.array(['1', '2', '3']),
'b': empty_list_array})
tbl = pa.Table.from_pandas(df)

result = tbl.to_pandas()

tm.assert_frame_equal(result, df)


def _fully_loaded_dataframe_example():
from distutils.version import LooseVersion
Expand Down

0 comments on commit 4a3e6e3

Please sign in to comment.