-
-
Notifications
You must be signed in to change notification settings - Fork 19k
Support multiplication of pd.ArrowDtype(pa.string()) and integral value where integral value is a series #56538
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
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -695,22 +695,23 @@ def _evaluate_op_method(self, other, op, arrow_funcs): | |
other = self._box_pa(other) | ||
|
||
if pa.types.is_string(pa_type) or pa.types.is_binary(pa_type): | ||
if op in [operator.add, roperator.radd, operator.mul, roperator.rmul]: | ||
if op in [operator.add, roperator.radd]: | ||
sep = pa.scalar("", type=pa_type) | ||
if op is operator.add: | ||
result = pc.binary_join_element_wise(self._pa_array, other, sep) | ||
elif op is roperator.radd: | ||
result = pc.binary_join_element_wise(other, self._pa_array, sep) | ||
else: | ||
if not ( | ||
isinstance(other, pa.Scalar) and pa.types.is_integer(other.type) | ||
): | ||
raise TypeError("Can only string multiply by an integer.") | ||
result = pc.binary_join_element_wise( | ||
*([self._pa_array] * other.as_py()), sep | ||
) | ||
return type(self)(result) | ||
|
||
elif op in [operator.mul, roperator.rmul]: | ||
result = type(self)._evaluate_binary_repeat(self._pa_array, other) | ||
return type(self)(result) | ||
elif ( | ||
pa.types.is_integer(pa_type) | ||
and (pa.types.is_string(other.type) or pa.types.is_binary(other.type)) | ||
and op in [operator.mul, roperator.rmul] | ||
): | ||
result = type(self)._evaluate_binary_repeat(other, self._pa_array) | ||
return type(self)(result) | ||
if ( | ||
isinstance(other, pa.Scalar) | ||
and pc.is_null(other).as_py() | ||
|
@@ -726,6 +727,13 @@ def _evaluate_op_method(self, other, op, arrow_funcs): | |
result = pc_func(self._pa_array, other) | ||
return type(self)(result) | ||
|
||
@staticmethod | ||
def _evaluate_binary_repeat(binary, integral): | ||
if not pa.types.is_integer(integral.type): | ||
rohanjain101 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
raise TypeError("Can only string multiply by an integer.") | ||
pa_integral = pc.if_else(pc.less(integral, 0), 0, integral) | ||
return pc.binary_repeat(binary, pa_integral) | ||
|
||
|
||
def _logical_method(self, other, op): | ||
# For integer types `^`, `|`, `&` are bitwise operators and return | ||
# integer types. Otherwise these are boolean ops. | ||
|
Uh oh!
There was an error while loading. Please reload this page.