Skip to content

CLN: remove no-longer-used ignore_failures in frame_apply #37851

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
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def frame_apply(
axis: Axis = 0,
raw: bool = False,
result_type: Optional[str] = None,
ignore_failures: bool = False,
args=None,
kwds=None,
):
Expand All @@ -43,7 +42,6 @@ def frame_apply(
func,
raw=raw,
result_type=result_type,
ignore_failures=ignore_failures,
args=args,
kwds=kwds,
)
Expand Down Expand Up @@ -84,13 +82,11 @@ def __init__(
func,
raw: bool,
result_type: Optional[str],
ignore_failures: bool,
args,
kwds,
):
self.obj = obj
self.raw = raw
self.ignore_failures = ignore_failures
self.args = args or ()
self.kwds = kwds or {}

Expand Down Expand Up @@ -283,29 +279,14 @@ def apply_series_generator(self) -> Tuple[ResType, "Index"]:

results = {}

if self.ignore_failures:
successes = []
with option_context("mode.chained_assignment", None):
for i, v in enumerate(series_gen):
try:
results[i] = self.f(v)
except Exception:
pass
else:
successes.append(i)

# so will work with MultiIndex
if len(successes) < len(res_index):
res_index = res_index.take(successes)

else:
with option_context("mode.chained_assignment", None):
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):
# If we have a view on v, we need to make a copy because
# series_generator will swap out the underlying data
results[i] = results[i].copy(deep=False)
# ignore SettingWithCopy here in case the user mutates
results[i] = self.f(v)
if isinstance(results[i], ABCSeries):
# If we have a view on v, we need to make a copy because
# series_generator will swap out the underlying data
results[i] = results[i].copy(deep=False)

return results, res_index

Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/frame/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pandas as pd
from pandas import DataFrame, MultiIndex, Series, Timestamp, date_range, notna
import pandas._testing as tm
from pandas.core.apply import frame_apply
from pandas.core.base import SpecificationError
from pandas.tests.frame.common import zip_frames

Expand Down Expand Up @@ -267,13 +266,6 @@ def test_apply_axis1(self, float_frame):
tapplied = float_frame.apply(np.mean, axis=1)
assert tapplied[d] == np.mean(float_frame.xs(d))

def test_apply_ignore_failures(self, float_string_frame):
result = frame_apply(
float_string_frame, np.mean, 0, ignore_failures=True
).apply_standard()
expected = float_string_frame._get_numeric_data().apply(np.mean)
tm.assert_series_equal(result, expected)

def test_apply_mixed_dtype_corner(self):
df = DataFrame({"A": ["foo"], "B": [1.0]})
result = df[:0].apply(np.mean, axis=1)
Expand Down