Skip to content

Commit

Permalink
fix(python): ensure pyarrow.compute module is loaded (#6353)
Browse files Browse the repository at this point in the history
  • Loading branch information
josh authored Jan 22, 2023
1 parent 5bc5122 commit f2e54b1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions py-polars/polars/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,9 +1178,11 @@ def pandas_to_pydf(


def coerce_arrow(array: pa.Array, rechunk: bool = True) -> pa.Array:
import pyarrow.compute as pc

# note: Decimal256 could not be cast to float
if isinstance(array.type, pa.Decimal128Type):
array = pa.compute.cast(array, pa.float64())
array = pc.cast(array, pa.float64())

if hasattr(array, "num_chunks") and array.num_chunks > 1 and rechunk:
# small integer keys can often not be combined, so let's already cast
Expand All @@ -1192,7 +1194,7 @@ def coerce_arrow(array: pa.Array, rechunk: bool = True) -> pa.Array:
or pa.types.is_uint16(array.type.index_type)
or pa.types.is_int32(array.type.index_type)
):
array = pa.compute.cast(
array = pc.cast(
array, pa.dictionary(pa.uint32(), pa.large_string())
).combine_chunks()
return array

0 comments on commit f2e54b1

Please sign in to comment.