PERF: BooleanArray._from_sequence_of_strings by lukemanley · Pull Request #50613 · pandas-dev/pandas (original) (raw)
Also removes the need to xfail when parsing a pyarrow array of strings.
import pandas as pd
import numpy as np
from pandas.core.arrays.boolean import BooleanArray
choices = BooleanArray._TRUE_VALUES.union(BooleanArray._FALSE_VALUES)
choices = np.array(list(choices), dtype=object)
strings = np.random.choice(choices, 10**5, replace=True)
%timeit BooleanArray._from_sequence_of_strings(strings)
# 43.4 ms ± 1.04 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) -> main
# 21.9 ms ± 120 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) -> PR