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

Support async for bulk operations #2

Open
pjbull opened this issue Feb 12, 2021 · 0 comments
Open

Support async for bulk operations #2

pjbull opened this issue Feb 12, 2021 · 0 comments

Comments

@pjbull
Copy link
Member

pjbull commented Feb 12, 2021

Lots of what we do in _to_apply here is either going to be disk (in the case of Path) or network (if we implement #1) bound and should benefit from doing it async.

def _elementwise(self, other, attr):
if isinstance(other, PathAccessor):
other = other._obj
other_array = np.array(other)
if other_array.ndim > 1:
raise ValueError(
"Can only do an elementwise operations with a 1d array, list, or Series."
)
if other_array.shape[0] != len(self._obj):
raise ValueError(
"Can only do an elementwise operation with arrays of the same length."
)
def _to_apply(this_elem, other_elem):
res = getattr(Path(this_elem), attr)(other_elem)
return res if not isinstance(res, Path) else str(res)
elementwise_result = pd.Series(
[
_to_apply(this_elem, other_elem)
for this_elem, other_elem in zip(self._obj.values, other_array)
],
index=self._obj.index,
)
return elementwise_result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant