Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): ensure pyarrow.compute module is loaded #6353

Merged
merged 1 commit into from
Jan 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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