Skip to content

PERF: ArrowExtensionArray._from_sequence_of_strings(dtype=pa.bool_()) #51730

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

Merged

Conversation

lukemanley
Copy link
Member

ArrowExtensionArray._from_sequence_of_strings currently depends on BooleanArray._from_sequence_of_strings to parse strings for boolean[pyarrow]. This removes the dependency on BooleanArray and uses pyarrow casting to accomplish the same thing. I've adding some logic around pyarrow's casting to match existing behavior of BooleanArray (assuming we want to maintain existing behavior?)

import pyarrow as pa
import numpy as np
from pandas.core.arrays.arrow.array import ArrowExtensionArray

N = 1_000_000
strings_np = np.random.choice(["true", "false", None], N, replace=True)
strings_pa = pa.array(strings_np, type=pa.string())

%timeit ArrowExtensionArray._from_sequence_of_strings(strings_np, dtype=pa.bool_())

# 200 ms ± 4.72 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)    -> main
# 54.5 ms ± 842 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)  -> PR

%timeit ArrowExtensionArray._from_sequence_of_strings(strings_pa, dtype=pa.bool_())

# 298 ms ± 3.45 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)    -> main
# 30.8 ms ± 1.1 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)  -> PR

@lukemanley lukemanley added Performance Memory or execution speed performance Arrow pyarrow functionality labels Mar 1, 2023
@mroeschke mroeschke added this to the 2.1 milestone Mar 6, 2023
@mroeschke mroeschke merged commit b1c6622 into pandas-dev:main Mar 6, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

@lukemanley lukemanley deleted the arrow-from-sequence-of-strings-bool branch March 17, 2023 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants