Skip to content

Commit 7ccac68

Browse files
authored
issue 48855 enable pylint C-type "disallowed-name " warning (#49379)
* remove from exclusions + cleanup * try foo variation, instead * revert change + exclude from linting * revert + exclude from linting * revert + exclude fron linting * more descriptive names * try assigning to itself * more test clean-up * try reverting with exclusion * more clean-up * revert
1 parent 6526e93 commit 7ccac68

File tree

21 files changed

+87
-78
lines changed

21 files changed

+87
-78
lines changed

asv_bench/benchmarks/attrs_caching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def setup(self):
1515
self.cur_index = self.df.index
1616

1717
def time_get_index(self):
18-
self.foo = self.df.index
18+
self.df.index
1919

2020
def time_set_index(self):
2121
self.df.index = self.cur_index

pandas/io/formats/style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,7 @@ def set_properties(self, subset: Subset | None = None, **kwargs) -> Styler:
29022902
return self.applymap(lambda x: values, subset=subset)
29032903

29042904
@Substitution(subset=subset)
2905-
def bar(
2905+
def bar( # pylint: disable=disallowed-name
29062906
self,
29072907
subset: Subset | None = None,
29082908
axis: Axis | None = 0,

pandas/plotting/_core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,9 @@ def line(self, x=None, y=None, **kwargs) -> PlotAccessor:
11311131
)
11321132
@Substitution(kind="bar")
11331133
@Appender(_bar_or_line_doc)
1134-
def bar(self, x=None, y=None, **kwargs) -> PlotAccessor:
1134+
def bar( # pylint: disable=disallowed-name
1135+
self, x=None, y=None, **kwargs
1136+
) -> PlotAccessor:
11351137
"""
11361138
Vertical bar plot.
11371139

pandas/tests/apply/test_frame_apply.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,18 +1516,18 @@ def test_aggregation_func_column_order():
15161516
columns=("att1", "att2", "att3"),
15171517
)
15181518

1519-
def foo(s):
1519+
def sum_div2(s):
15201520
return s.sum() / 2
15211521

1522-
aggs = ["sum", foo, "count", "min"]
1522+
aggs = ["sum", sum_div2, "count", "min"]
15231523
result = df.agg(aggs)
15241524
expected = DataFrame(
15251525
{
15261526
"att1": [21.0, 10.5, 6.0, 1.0],
15271527
"att2": [18.0, 9.0, 6.0, 0.0],
15281528
"att3": [17.0, 8.5, 6.0, 0.0],
15291529
},
1530-
index=["sum", "foo", "count", "min"],
1530+
index=["sum", "sum_div2", "count", "min"],
15311531
)
15321532
tm.assert_frame_equal(result, expected)
15331533

@@ -1548,13 +1548,13 @@ def test_nuisance_depr_passes_through_warnings():
15481548
# sure if some other warnings were raised, they get passed through to
15491549
# the user.
15501550

1551-
def foo(x):
1551+
def expected_warning(x):
15521552
warnings.warn("Hello, World!")
15531553
return x.sum()
15541554

15551555
df = DataFrame({"a": [1, 2, 3]})
15561556
with tm.assert_produces_warning(UserWarning, match="Hello, World!"):
1557-
df.agg([foo])
1557+
df.agg([expected_warning])
15581558

15591559

15601560
def test_apply_type():

pandas/tests/base/test_constructors.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ def constructor(request):
4343

4444
class TestPandasDelegate:
4545
class Delegator:
46-
_properties = ["foo"]
47-
_methods = ["bar"]
46+
_properties = ["prop"]
47+
_methods = ["test_method"]
4848

49-
def _set_foo(self, value):
50-
self.foo = value
49+
def _set_prop(self, value):
50+
self.prop = value
5151

52-
def _get_foo(self):
53-
return self.foo
52+
def _get_prop(self):
53+
return self.prop
5454

55-
foo = property(_get_foo, _set_foo, doc="foo property")
55+
prop = property(_get_prop, _set_prop, doc="foo property")
5656

57-
def bar(self, *args, **kwargs):
58-
"""a test bar method"""
57+
def test_method(self, *args, **kwargs):
58+
"""a test method"""
5959

6060
class Delegate(PandasDelegate, PandasObject):
6161
def __init__(self, obj) -> None:
@@ -77,17 +77,17 @@ def test_invalid_delegation(self):
7777

7878
delegate = self.Delegate(self.Delegator())
7979

80-
msg = "You cannot access the property foo"
80+
msg = "You cannot access the property prop"
8181
with pytest.raises(TypeError, match=msg):
82-
delegate.foo
82+
delegate.prop
8383

84-
msg = "The property foo cannot be set"
84+
msg = "The property prop cannot be set"
8585
with pytest.raises(TypeError, match=msg):
86-
delegate.foo = 5
86+
delegate.prop = 5
8787

88-
msg = "You cannot access the property foo"
88+
msg = "You cannot access the property prop"
8989
with pytest.raises(TypeError, match=msg):
90-
delegate.foo()
90+
delegate.prop()
9191

9292
@pytest.mark.skipif(PYPY, reason="not relevant for PyPy")
9393
def test_memory_usage(self):

pandas/tests/dtypes/test_inference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ def test_is_list_like_disallow_sets(maybe_list_like):
203203
def test_is_list_like_recursion():
204204
# GH 33721
205205
# interpreter would crash with SIGABRT
206-
def foo():
206+
def list_like():
207207
inference.is_list_like([])
208-
foo()
208+
list_like()
209209

210210
rec_limit = sys.getrecursionlimit()
211211
try:
212212
# Limit to avoid stack overflow on Windows CI
213213
sys.setrecursionlimit(100)
214214
with tm.external_error_raised(RecursionError):
215-
foo()
215+
list_like()
216216
finally:
217217
sys.setrecursionlimit(rec_limit)
218218

pandas/tests/frame/test_subclass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def test_subclass_attr_err_propagation(self):
138138
# GH 11808
139139
class A(DataFrame):
140140
@property
141-
def bar(self):
141+
def nonexistence(self):
142142
return self.i_dont_exist
143143

144144
with pytest.raises(AttributeError, match=".*i_dont_exist.*"):
145-
A().bar
145+
A().nonexistence
146146

147147
def test_subclass_align(self):
148148
# GH 12983

pandas/tests/groupby/aggregate/test_aggregate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ def test_aggregate_item_by_item(df):
283283

284284
aggfun_0 = lambda ser: ser.size
285285
result = grouped.agg(aggfun_0)
286-
foo = (df.A == "foo").sum()
287-
bar = (df.A == "bar").sum()
286+
foosum = (df.A == "foo").sum()
287+
barsum = (df.A == "bar").sum()
288288
K = len(result.columns)
289289

290290
# GH5782
291-
exp = Series(np.array([foo] * K), index=list("BCD"), name="foo")
291+
exp = Series(np.array([foosum] * K), index=list("BCD"), name="foo")
292292
tm.assert_series_equal(result.xs("foo"), exp)
293293

294-
exp = Series(np.array([bar] * K), index=list("BCD"), name="bar")
294+
exp = Series(np.array([barsum] * K), index=list("BCD"), name="bar")
295295
tm.assert_almost_equal(result.xs("bar"), exp)
296296

297297
def aggfun_1(ser):
@@ -417,10 +417,10 @@ def test_more_flexible_frame_multi_function(df):
417417
expected = grouped.aggregate({"C": np.mean, "D": [np.mean, np.std]})
418418
tm.assert_frame_equal(result, expected)
419419

420-
def foo(x):
420+
def numpymean(x):
421421
return np.mean(x)
422422

423-
def bar(x):
423+
def numpystd(x):
424424
return np.std(x, ddof=1)
425425

426426
# this uses column selection & renaming
@@ -430,7 +430,7 @@ def bar(x):
430430
grouped.aggregate(d)
431431

432432
# But without renaming, these functions are OK
433-
d = {"C": [np.mean], "D": [foo, bar]}
433+
d = {"C": [np.mean], "D": [numpymean, numpystd]}
434434
grouped.aggregate(d)
435435

436436

pandas/tests/groupby/test_groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ def freduce(group):
16161616
assert group.name is not None
16171617
return group.sum()
16181618

1619-
def foo(x):
1619+
def freducex(x):
16201620
return freduce(x)
16211621

16221622
grouped = df.groupby(grouper, group_keys=False)
@@ -1629,7 +1629,7 @@ def foo(x):
16291629

16301630
grouped["C"].apply(f)
16311631
grouped["C"].aggregate(freduce)
1632-
grouped["C"].aggregate([freduce, foo])
1632+
grouped["C"].aggregate([freduce, freducex])
16331633
grouped["C"].transform(f)
16341634

16351635

pandas/tests/indexes/multi/test_integrity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ def test_level_setting_resets_attributes():
233233

234234
def test_rangeindex_fallback_coercion_bug():
235235
# GH 12893
236-
foo = pd.DataFrame(np.arange(100).reshape((10, 10)))
237-
bar = pd.DataFrame(np.arange(100).reshape((10, 10)))
238-
df = pd.concat({"foo": foo.stack(), "bar": bar.stack()}, axis=1)
236+
df1 = pd.DataFrame(np.arange(100).reshape((10, 10)))
237+
df2 = pd.DataFrame(np.arange(100).reshape((10, 10)))
238+
df = pd.concat({"df1": df1.stack(), "df2": df2.stack()}, axis=1)
239239
df.index.names = ["fizz", "buzz"]
240240

241241
str(df)
242242
expected = pd.DataFrame(
243-
{"bar": np.arange(100), "foo": np.arange(100)},
243+
{"df2": np.arange(100), "df1": np.arange(100)},
244244
index=MultiIndex.from_product([range(10), range(10)], names=["fizz", "buzz"]),
245245
)
246246
tm.assert_frame_equal(df, expected, check_like=True)

0 commit comments

Comments
 (0)