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

CLN: Remove leftover partial-result code from apply #35397

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 4 additions & 17 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,33 +252,20 @@ def apply_broadcast(self, target: "DataFrame") -> "DataFrame":
return result

def apply_standard(self):

# partial result that may be returned from reduction
partial_result = None

# compute the result using the series generator,
# use the result computed while trying to reduce if available.
results, res_index = self.apply_series_generator(partial_result)
results, res_index = self.apply_series_generator()

# wrap results
return self.wrap_results(results, res_index)

def apply_series_generator(self, partial_result=None) -> Tuple[ResType, "Index"]:
def apply_series_generator(self) -> Tuple[ResType, "Index"]:
series_gen = self.series_generator
res_index = self.result_index

results = {}

# If a partial result was already computed,
# use it instead of running on the first element again
series_gen_enumeration = enumerate(series_gen)
if partial_result is not None:
i, v = next(series_gen_enumeration)
results[i] = partial_result

if self.ignore_failures:
successes = []
for i, v in series_gen_enumeration:
for i, v in enumerate(series_gen):
try:
results[i] = self.f(v)
except Exception:
Expand All @@ -292,7 +279,7 @@ def apply_series_generator(self, partial_result=None) -> Tuple[ResType, "Index"]

else:
with option_context("mode.chained_assignment", None):
for i, v in series_gen_enumeration:
for i, v in enumerate(series_gen):
# ignore SettingWithCopy here in case the user mutates
results[i] = self.f(v)
if isinstance(results[i], ABCSeries):
Expand Down