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

21 files changed

+87
-78
lines changed

asv_bench/benchmarks/attrs_caching.py

+1-1
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

+1-1
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

+3-1
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

+5-5
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

+15-15
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

+3-3
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

+2-2
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

+7-7
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

+2-2
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

+4-4
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)

pandas/tests/io/formats/style/test_style.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,10 @@ def test_apply_dataframe_return(self, index, columns):
653653
)
654654
@pytest.mark.parametrize("axis", [0, 1])
655655
def test_apply_subset(self, slice_, axis, df):
656-
def h(x, foo="bar"):
657-
return Series(f"color: {foo}", index=x.index, name=x.name)
656+
def h(x, color="bar"):
657+
return Series(f"color: {color}", index=x.index, name=x.name)
658658

659-
result = df.style.apply(h, axis=axis, subset=slice_, foo="baz")._compute().ctx
659+
result = df.style.apply(h, axis=axis, subset=slice_, color="baz")._compute().ctx
660660
expected = {
661661
(r, c): [("color", "baz")]
662662
for r, row in enumerate(df.index)

pandas/tests/io/test_sql.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -2181,26 +2181,26 @@ def test_connectable_issue_example(self):
21812181
# https://github.com/pandas-dev/pandas/issues/10104
21822182
from sqlalchemy.engine import Engine
21832183

2184-
def foo(connection):
2184+
def test_select(connection):
21852185
query = "SELECT test_foo_data FROM test_foo_data"
21862186
return sql.read_sql_query(query, con=connection)
21872187

2188-
def bar(connection, data):
2188+
def test_append(connection, data):
21892189
data.to_sql(name="test_foo_data", con=connection, if_exists="append")
21902190

2191-
def baz(conn):
2191+
def test_connectable(conn):
21922192
# https://github.com/sqlalchemy/sqlalchemy/commit/
21932193
# 00b5c10846e800304caa86549ab9da373b42fa5d#r48323973
2194-
foo_data = foo(conn)
2195-
bar(conn, foo_data)
2194+
foo_data = test_select(conn)
2195+
test_append(conn, foo_data)
21962196

21972197
def main(connectable):
21982198
if isinstance(connectable, Engine):
21992199
with connectable.connect() as conn:
22002200
with conn.begin():
2201-
baz(conn)
2201+
test_connectable(conn)
22022202
else:
2203-
baz(connectable)
2203+
test_connectable(connectable)
22042204

22052205
assert (
22062206
DataFrame({"test_foo_data": [0, 1, 2]}).to_sql("test_foo_data", self.conn)
@@ -2373,21 +2373,21 @@ def test_row_object_is_named_tuple(self):
23732373
class Test(BaseModel):
23742374
__tablename__ = "test_frame"
23752375
id = Column(Integer, primary_key=True)
2376-
foo = Column(String(50))
2376+
string_column = Column(String(50))
23772377

23782378
BaseModel.metadata.create_all(self.conn)
23792379
Session = sessionmaker(bind=self.conn)
23802380
with Session() as session:
2381-
df = DataFrame({"id": [0, 1], "foo": ["hello", "world"]})
2381+
df = DataFrame({"id": [0, 1], "string_column": ["hello", "world"]})
23822382
assert (
23832383
df.to_sql("test_frame", con=self.conn, index=False, if_exists="replace")
23842384
== 2
23852385
)
23862386
session.commit()
2387-
foo = session.query(Test.id, Test.foo)
2388-
df = DataFrame(foo)
2387+
test_query = session.query(Test.id, Test.string_column)
2388+
df = DataFrame(test_query)
23892389

2390-
assert list(df.columns) == ["id", "foo"]
2390+
assert list(df.columns) == ["id", "string_column"]
23912391

23922392

23932393
class _TestMySQLAlchemy:

pandas/tests/resample/test_period_index.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,11 @@ def test_resample_with_dst_time_change(self):
605605

606606
def test_resample_bms_2752(self):
607607
# GH2753
608-
foo = Series(index=pd.bdate_range("20000101", "20000201"), dtype=np.float64)
609-
res1 = foo.resample("BMS").mean()
610-
res2 = foo.resample("BMS").mean().resample("B").mean()
608+
timeseries = Series(
609+
index=pd.bdate_range("20000101", "20000201"), dtype=np.float64
610+
)
611+
res1 = timeseries.resample("BMS").mean()
612+
res2 = timeseries.resample("BMS").mean().resample("B").mean()
611613
assert res1.index[0] == Timestamp("20000103")
612614
assert res1.index[0] == res2.index[0]
613615

pandas/tests/reshape/concat/test_empty.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class TestEmptyConcat:
1616
def test_handle_empty_objects(self, sort):
1717
df = DataFrame(np.random.randn(10, 4), columns=list("abcd"))
1818

19-
baz = df[:5].copy()
20-
baz["foo"] = "bar"
19+
dfcopy = df[:5].copy()
20+
dfcopy["foo"] = "bar"
2121
empty = df[5:5]
2222

23-
frames = [baz, empty, empty, df[5:]]
23+
frames = [dfcopy, empty, empty, df[5:]]
2424
concatted = concat(frames, axis=0, sort=sort)
2525

2626
expected = df.reindex(columns=["a", "b", "c", "d", "foo"])

pandas/tests/reshape/concat/test_series.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,30 @@ def test_concat_series_name_npscalar_tuple(self, s1name, s2name):
120120

121121
def test_concat_series_partial_columns_names(self):
122122
# GH10698
123-
foo = Series([1, 2], name="foo")
124-
bar = Series([1, 2])
125-
baz = Series([4, 5])
123+
named_series = Series([1, 2], name="foo")
124+
unnamed_series1 = Series([1, 2])
125+
unnamed_series2 = Series([4, 5])
126126

127-
result = concat([foo, bar, baz], axis=1)
127+
result = concat([named_series, unnamed_series1, unnamed_series2], axis=1)
128128
expected = DataFrame(
129129
{"foo": [1, 2], 0: [1, 2], 1: [4, 5]}, columns=["foo", 0, 1]
130130
)
131131
tm.assert_frame_equal(result, expected)
132132

133-
result = concat([foo, bar, baz], axis=1, keys=["red", "blue", "yellow"])
133+
result = concat(
134+
[named_series, unnamed_series1, unnamed_series2],
135+
axis=1,
136+
keys=["red", "blue", "yellow"],
137+
)
134138
expected = DataFrame(
135139
{"red": [1, 2], "blue": [1, 2], "yellow": [4, 5]},
136140
columns=["red", "blue", "yellow"],
137141
)
138142
tm.assert_frame_equal(result, expected)
139143

140-
result = concat([foo, bar, baz], axis=1, ignore_index=True)
144+
result = concat(
145+
[named_series, unnamed_series1, unnamed_series2], axis=1, ignore_index=True
146+
)
141147
expected = DataFrame({0: [1, 2], 1: [1, 2], 2: [4, 5]})
142148
tm.assert_frame_equal(result, expected)
143149

pandas/tests/reshape/test_pivot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2109,9 +2109,9 @@ def test_pivot_table_no_column_raises(self):
21092109
def agg(arr):
21102110
return np.mean(arr)
21112111

2112-
foo = DataFrame({"X": [0, 0, 1, 1], "Y": [0, 1, 0, 1], "Z": [10, 20, 30, 40]})
2112+
df = DataFrame({"X": [0, 0, 1, 1], "Y": [0, 1, 0, 1], "Z": [10, 20, 30, 40]})
21132113
with pytest.raises(KeyError, match="notpresent"):
2114-
foo.pivot_table("notpresent", "X", "Y", aggfunc=agg)
2114+
df.pivot_table("notpresent", "X", "Y", aggfunc=agg)
21152115

21162116
def test_pivot_table_multiindex_columns_doctest_case(self):
21172117
# The relevant characteristic is that the call

pandas/tests/util/test_deprecate_nonkeyword_arguments.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_i_signature():
140140

141141
class Foo:
142142
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "bar"])
143-
def baz(self, bar=None, foobar=None):
143+
def baz(self, bar=None, foobar=None): # pylint: disable=disallowed-name
144144
...
145145

146146

0 commit comments

Comments
 (0)