Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 331a717

Browse files
OswinCwenleix
authored andcommitted
Fix a bug in combining chunks in a table (#122)
Summary: Pull Request resolved: #122 `combine_chunks()` is const. Forgot to update the handle with the returned from `combine_chunks()` Reviewed By: vancexu Differential Revision: D33234089 fbshipit-source-id: b72069ba513098cb6284f1e04d1b25675398ba0f
1 parent 6b93e1b commit 331a717

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

torcharrow/interop_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _from_arrow_table(
6868
# from_arrow for struct type
6969

7070
# May not be zero-copy here if multiple chunks need to be combined
71-
table.combine_chunks()
71+
table = table.combine_chunks()
7272

7373
df_data = {}
7474
for i in range(0, len(table.schema)):

torcharrow/test/test_arrow_interop.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ def base_test_from_arrow_table(self):
118118
)
119119
self.assertEqual(list(df[ta_field.name]), pt[i].to_pylist())
120120

121+
def base_test_from_arrow_table_with_chunked_arrays(self):
122+
chunked = pa.chunked_array([[1, 2, 3], [4, 5, 6]])
123+
pt = pa.table({"f1": chunked})
124+
df = ta.from_arrow(pt, device=self.device)
125+
self.assertTrue(isinstance(df, IDataFrame))
126+
self.assertTrue(dt.is_struct(df.dtype))
127+
self.assertEqual(len(df), len(pt))
128+
for (i, ta_field) in enumerate(df.dtype.fields):
129+
pa_field = pt.schema.field(i)
130+
self.assertEqual(ta_field.name, pa_field.name)
131+
self.assertEqual(
132+
ta_field.dtype, _arrowtype_to_dtype(pa_field.type, pa_field.nullable)
133+
)
134+
self.assertEqual(list(df[ta_field.name]), pt[i].to_pylist())
135+
121136
def _test_to_arrow_array_numeric(
122137
self, pydata: List, dtype: dt.DType, expected_arrowtype: pa.DataType
123138
):

torcharrow/test/test_arrow_interop_cpu.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_from_arrow_array_string(self):
2323
def test_from_arrow_table(self):
2424
return self.base_test_from_arrow_table()
2525

26+
def test_from_arrow_table_with_chunked_arrays(self):
27+
return self.base_test_from_arrow_table_with_chunked_arrays()
28+
2629
def test_to_arrow_array_boolean(self):
2730
return self.base_test_to_arrow_array_boolean
2831

0 commit comments

Comments
 (0)