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

dont use take with arrow #2336

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
15 changes: 12 additions & 3 deletions packages/vaex-core/vaex/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,17 @@ def __getitem__(self, slice):
# arrow and numpy do not like the negative indices, so we set them to 0
take_indices = indices.copy()
take_indices[mask] = 0
if isinstance(ar_unfiltered, supported_arrow_array_types):
ar = ar_unfiltered.take(vaex.array_types.to_arrow(take_indices))
# Don't use .take in arrow anymore
# https://issues.apache.org/jira/browse/ARROW-9773
# slice is zero-copy
if isinstance(ar_unfiltered, pa.Array):
ar = pa.concat_arrays(
[ar_unfiltered.slice(i, 1) for i in take_indices]
)
elif isinstance(ar_unfiltered, pa.ChunkedArray):
ar = pa.concat_arrays(
[ar_unfiltered.slice(i, 1).combine_chunks() for i in take_indices]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Don't use .take in arrow anymore
# https://issues.apache.org/jira/browse/ARROW-9773
# slice is zero-copy
if isinstance(ar_unfiltered, pa.Array):
ar = pa.concat_arrays(
[ar_unfiltered.slice(i, 1) for i in take_indices]
)
elif isinstance(ar_unfiltered, pa.ChunkedArray):
ar = pa.concat_arrays(
[ar_unfiltered.slice(i, 1).combine_chunks() for i in take_indices]
)
if isinstance(ar_unfiltered, pa.Array):
ar = ar_unfiltered.take(vaex.array_types.to_arrow(take_indices))
elif isinstance(ar_unfiltered, pa.ChunkedArray):
# Don't use .take in arrow for chunked arrays
# https://issues.apache.org/jira/browse/ARROW-9773
# slice is zero-copy
ar = pa.concat_arrays(
[ar_unfiltered.slice(i, 1).combine_chunks() for i in take_indices]
)

it is only an issue for chunked arrays right?
Maybe the best place to put this is vaex.array_types.take ?
There is already a take function there, and if all places in vaex uses that function, we have a nice central place where we can solve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maartenbreddels i do not think this is only an issue for chunked_arrays, I think it's an issue with take broadly. I definitely like the idea of moving it down to a centralized place, but I think no matter the array type, you need to replace take with slice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://issues.apache.org/jira/browse/ARROW-9773 only talks about chunked arrays, and I also think it's only a problem for that (since it's more complex).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i'll take your word on this one, you certainly know more here. I'll move this into the vaex array_types.take

else:
ar = ar_unfiltered[take_indices]
assert not np.ma.isMaskedArray(indices)
Expand Down Expand Up @@ -825,4 +834,4 @@ def get_mask(self):
return self.string_sequence.mask()

def astype(self, type):
return self.to_numpy().astype(type)
return self.to_numpy().astype(type)