Skip to content

Enable get-attr-with-constant (B009) #60862

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 2 commits into from
Feb 6, 2025
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
2 changes: 1 addition & 1 deletion pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any)
reconstruct_axes = dict(zip(self._AXIS_ORDERS, self.axes))

if self.ndim == 1:
names = {getattr(x, "name") for x in inputs if hasattr(x, "name")}
names = {x.name for x in inputs if hasattr(x, "name")}
name = names.pop() if len(names) == 1 else None
reconstruct_kwargs = {"name": name}
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def is_full_slice(obj, line: int) -> bool:
def get_callable_name(obj):
# typical case has name
if hasattr(obj, "__name__"):
return getattr(obj, "__name__")
return obj.__name__
# some objects don't; could recurse
if isinstance(obj, partial):
return get_callable_name(obj.func)
Expand Down
10 changes: 4 additions & 6 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def apply(
more details.
"""
self._todo.append(
(lambda instance: getattr(instance, "_apply"), (func, axis, subset), kwargs)
(lambda instance: instance._apply, (func, axis, subset), kwargs)
)
return self

Expand Down Expand Up @@ -2128,7 +2128,7 @@ def apply_index(
"""
self._todo.append(
(
lambda instance: getattr(instance, "_apply_index"),
lambda instance: instance._apply_index,
(func, axis, level, "apply"),
kwargs,
)
Expand Down Expand Up @@ -2157,7 +2157,7 @@ def map_index(
) -> Styler:
self._todo.append(
(
lambda instance: getattr(instance, "_apply_index"),
lambda instance: instance._apply_index,
(func, axis, level, "map"),
kwargs,
)
Expand Down Expand Up @@ -2230,9 +2230,7 @@ def map(self, func: Callable, subset: Subset | None = None, **kwargs) -> Styler:
See `Table Visualization <../../user_guide/style.ipynb>`_ user guide for
more details.
"""
self._todo.append(
(lambda instance: getattr(instance, "_map"), (func, subset), kwargs)
)
self._todo.append((lambda instance: instance._map, (func, subset), kwargs))
return self

def set_table_attributes(self, attributes: str) -> Styler:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def test_timedelta_methods(method):
operator.methodcaller("add_categories", ["c"]),
operator.methodcaller("as_ordered"),
operator.methodcaller("as_unordered"),
lambda x: getattr(x, "codes"),
lambda x: x.codes,
operator.methodcaller("remove_categories", "a"),
operator.methodcaller("remove_unused_categories"),
operator.methodcaller("rename_categories", {"a": "A", "b": "B"}),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ def test_empty_df(method, op):
# GH 47985
empty_df = DataFrame({"a": [], "b": []})
gb = empty_df.groupby("a", group_keys=True)
group = getattr(gb, "b")
group = gb.b

result = getattr(group, method)(op)
expected = Series(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_attr_wrapper(ts):
# make sure raises error
msg = "'SeriesGroupBy' object has no attribute 'foo'"
with pytest.raises(AttributeError, match=msg):
getattr(grouped, "foo")
grouped.foo


def test_frame_groupby(tsframe):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_getattr(setup_path):
# test attribute access
result = store.a
tm.assert_series_equal(result, s)
result = getattr(store, "a")
result = store.a
tm.assert_series_equal(result, s)

df = DataFrame(
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ ignore = [
"B007",
# controversial
"B008",
# setattr is used to side-step mypy
"B009",
# getattr is used to side-step mypy
"B010",
# tests use comparisons but not their returned value
Expand Down
Loading