Skip to content

Commit 4c2aadc

Browse files
[python] Fix old pyarrow bug triggers (#4433)
* Do not cast timestamp to int array * PRovide timestamp conversion workaround
1 parent a60c8f1 commit 4c2aadc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

apis/python/src/tiledbsoma/_dataframe.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,17 @@ def _cast_domain_to_cpp_type(
10161016
return None
10171017

10181018
if index_column_name in schema.names:
1019+
# Fow older version of pyarrow creating a RecordBatch with timestamp as input fails
1020+
# The following workaround directly get the int representation of timestamp if the types match
1021+
# otherwise throw an error
1022+
if isinstance(slot_domain[0], pa.TimestampScalar) and isinstance(
1023+
schema.field(index_column_name).type, pa.TimestampType
1024+
):
1025+
if slot_domain[0].type != schema.field(index_column_name).type:
1026+
raise TypeError(f"Type mismatch between domain and schema for column '{index_column_name}'")
1027+
1028+
return slot_domain[0].value, slot_domain[1].value
1029+
10191030
domain_array = pa.RecordBatch.from_pydict(
10201031
{index_column_name: slot_domain}, pa.schema([schema.field(index_column_name)])
10211032
)

apis/python/tests/test_io.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_write_arrow_table(tmp_path, num_rows, cap_nbytes, schema):
5151
Additional focus-testing for tiledbsoma.io._write_arrow_table
5252
"""
5353

54-
if pa.__version__ == "11.0.0" and num_rows == 0 and "bool_enum" in schema.names():
54+
if pa.__version__ == "11.0.0" and num_rows == 0 and "bool_enum" in schema.names:
5555
pytest.skip("Skip due to bug with empty dictionaries.")
5656

5757
pydict = {}
@@ -101,6 +101,9 @@ def test_write_arrow_table_enum_to_values(tmp_path, num_rows, cap_nbytes):
101101
Additional focus-testing for tiledbsoma.io._write_arrow_table
102102
"""
103103

104+
if pa.__version__ == "11.0.0" and num_rows == 0:
105+
pytest.skip("Skip due to bug with empty dictionaries.")
106+
104107
array_schema = pa.schema(
105108
[
106109
("bool", pa.bool_()),

0 commit comments

Comments
 (0)