Skip to content

Commit bf31347

Browse files
STYLE: Resolved Inconsistent namespace (#40286)
* STYLE: Inconsistent namespace - tools (#39992) * Pre-Commit Fixes * STYLE: Resolved Inconsistent namespace except test_algos.py - (#39992) * STYLE: Resolved Inconsistent namespace by excluding test_algos.py * test_algos.py fixes * Updated test_algos.py * STYLE: inconsistent-namespace-usage fixes * updated test_interval.py * FIX: Improved varible names * test_interval.py fixes * FIX: Resolved confusing variable names * test_string.py fixes * getitem.py fixes * rename more variables to arr Co-authored-by: Marco Gorelli <[email protected]>
1 parent 024a838 commit bf31347

File tree

18 files changed

+154
-159
lines changed

18 files changed

+154
-159
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ repos:
9595
entry: python scripts/check_for_inconsistent_pandas_namespace.py
9696
language: python
9797
types: [python]
98-
files: ^pandas/tests/frame/
98+
files: ^pandas/tests/
9999
- id: incorrect-code-directives
100100
name: Check for incorrect code block or IPython directives
101101
language: pygrep

pandas/tests/arithmetic/test_interval.py

+47-45
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def left_right_dtypes(request):
5050

5151

5252
@pytest.fixture
53-
def array(left_right_dtypes):
53+
def interval_array(left_right_dtypes):
5454
"""
5555
Fixture to generate an IntervalArray of various dtypes containing NA if possible
5656
"""
@@ -98,42 +98,42 @@ def interval_constructor(self, request):
9898
"""
9999
return request.param
100100

101-
def elementwise_comparison(self, op, array, other):
101+
def elementwise_comparison(self, op, interval_array, other):
102102
"""
103103
Helper that performs elementwise comparisons between `array` and `other`
104104
"""
105-
other = other if is_list_like(other) else [other] * len(array)
106-
expected = np.array([op(x, y) for x, y in zip(array, other)])
105+
other = other if is_list_like(other) else [other] * len(interval_array)
106+
expected = np.array([op(x, y) for x, y in zip(interval_array, other)])
107107
if isinstance(other, Series):
108108
return Series(expected, index=other.index)
109109
return expected
110110

111-
def test_compare_scalar_interval(self, op, array):
111+
def test_compare_scalar_interval(self, op, interval_array):
112112
# matches first interval
113-
other = array[0]
114-
result = op(array, other)
115-
expected = self.elementwise_comparison(op, array, other)
113+
other = interval_array[0]
114+
result = op(interval_array, other)
115+
expected = self.elementwise_comparison(op, interval_array, other)
116116
tm.assert_numpy_array_equal(result, expected)
117117

118118
# matches on a single endpoint but not both
119-
other = Interval(array.left[0], array.right[1])
120-
result = op(array, other)
121-
expected = self.elementwise_comparison(op, array, other)
119+
other = Interval(interval_array.left[0], interval_array.right[1])
120+
result = op(interval_array, other)
121+
expected = self.elementwise_comparison(op, interval_array, other)
122122
tm.assert_numpy_array_equal(result, expected)
123123

124124
def test_compare_scalar_interval_mixed_closed(self, op, closed, other_closed):
125-
array = IntervalArray.from_arrays(range(2), range(1, 3), closed=closed)
125+
interval_array = IntervalArray.from_arrays(range(2), range(1, 3), closed=closed)
126126
other = Interval(0, 1, closed=other_closed)
127127

128-
result = op(array, other)
129-
expected = self.elementwise_comparison(op, array, other)
128+
result = op(interval_array, other)
129+
expected = self.elementwise_comparison(op, interval_array, other)
130130
tm.assert_numpy_array_equal(result, expected)
131131

132-
def test_compare_scalar_na(self, op, array, nulls_fixture, request):
133-
result = op(array, nulls_fixture)
134-
expected = self.elementwise_comparison(op, array, nulls_fixture)
132+
def test_compare_scalar_na(self, op, interval_array, nulls_fixture, request):
133+
result = op(interval_array, nulls_fixture)
134+
expected = self.elementwise_comparison(op, interval_array, nulls_fixture)
135135

136-
if nulls_fixture is pd.NA and array.dtype.subtype != "int64":
136+
if nulls_fixture is pd.NA and interval_array.dtype.subtype != "int64":
137137
mark = pytest.mark.xfail(
138138
reason="broken for non-integer IntervalArray; see GH 31882"
139139
)
@@ -154,38 +154,40 @@ def test_compare_scalar_na(self, op, array, nulls_fixture, request):
154154
Period("2017-01-01", "D"),
155155
],
156156
)
157-
def test_compare_scalar_other(self, op, array, other):
158-
result = op(array, other)
159-
expected = self.elementwise_comparison(op, array, other)
157+
def test_compare_scalar_other(self, op, interval_array, other):
158+
result = op(interval_array, other)
159+
expected = self.elementwise_comparison(op, interval_array, other)
160160
tm.assert_numpy_array_equal(result, expected)
161161

162-
def test_compare_list_like_interval(self, op, array, interval_constructor):
162+
def test_compare_list_like_interval(self, op, interval_array, interval_constructor):
163163
# same endpoints
164-
other = interval_constructor(array.left, array.right)
165-
result = op(array, other)
166-
expected = self.elementwise_comparison(op, array, other)
164+
other = interval_constructor(interval_array.left, interval_array.right)
165+
result = op(interval_array, other)
166+
expected = self.elementwise_comparison(op, interval_array, other)
167167
tm.assert_equal(result, expected)
168168

169169
# different endpoints
170-
other = interval_constructor(array.left[::-1], array.right[::-1])
171-
result = op(array, other)
172-
expected = self.elementwise_comparison(op, array, other)
170+
other = interval_constructor(
171+
interval_array.left[::-1], interval_array.right[::-1]
172+
)
173+
result = op(interval_array, other)
174+
expected = self.elementwise_comparison(op, interval_array, other)
173175
tm.assert_equal(result, expected)
174176

175177
# all nan endpoints
176178
other = interval_constructor([np.nan] * 4, [np.nan] * 4)
177-
result = op(array, other)
178-
expected = self.elementwise_comparison(op, array, other)
179+
result = op(interval_array, other)
180+
expected = self.elementwise_comparison(op, interval_array, other)
179181
tm.assert_equal(result, expected)
180182

181183
def test_compare_list_like_interval_mixed_closed(
182184
self, op, interval_constructor, closed, other_closed
183185
):
184-
array = IntervalArray.from_arrays(range(2), range(1, 3), closed=closed)
186+
interval_array = IntervalArray.from_arrays(range(2), range(1, 3), closed=closed)
185187
other = interval_constructor(range(2), range(1, 3), closed=other_closed)
186188

187-
result = op(array, other)
188-
expected = self.elementwise_comparison(op, array, other)
189+
result = op(interval_array, other)
190+
expected = self.elementwise_comparison(op, interval_array, other)
189191
tm.assert_equal(result, expected)
190192

191193
@pytest.mark.parametrize(
@@ -206,17 +208,17 @@ def test_compare_list_like_interval_mixed_closed(
206208
),
207209
],
208210
)
209-
def test_compare_list_like_object(self, op, array, other):
210-
result = op(array, other)
211-
expected = self.elementwise_comparison(op, array, other)
211+
def test_compare_list_like_object(self, op, interval_array, other):
212+
result = op(interval_array, other)
213+
expected = self.elementwise_comparison(op, interval_array, other)
212214
tm.assert_numpy_array_equal(result, expected)
213215

214-
def test_compare_list_like_nan(self, op, array, nulls_fixture, request):
216+
def test_compare_list_like_nan(self, op, interval_array, nulls_fixture, request):
215217
other = [nulls_fixture] * 4
216-
result = op(array, other)
217-
expected = self.elementwise_comparison(op, array, other)
218+
result = op(interval_array, other)
219+
expected = self.elementwise_comparison(op, interval_array, other)
218220

219-
if nulls_fixture is pd.NA and array.dtype.subtype != "i8":
221+
if nulls_fixture is pd.NA and interval_array.dtype.subtype != "i8":
220222
reason = "broken for non-integer IntervalArray; see GH 31882"
221223
mark = pytest.mark.xfail(reason=reason)
222224
request.node.add_marker(mark)
@@ -239,18 +241,18 @@ def test_compare_list_like_nan(self, op, array, nulls_fixture, request):
239241
],
240242
ids=lambda x: str(x.dtype),
241243
)
242-
def test_compare_list_like_other(self, op, array, other):
243-
result = op(array, other)
244-
expected = self.elementwise_comparison(op, array, other)
244+
def test_compare_list_like_other(self, op, interval_array, other):
245+
result = op(interval_array, other)
246+
expected = self.elementwise_comparison(op, interval_array, other)
245247
tm.assert_numpy_array_equal(result, expected)
246248

247249
@pytest.mark.parametrize("length", [1, 3, 5])
248250
@pytest.mark.parametrize("other_constructor", [IntervalArray, list])
249251
def test_compare_length_mismatch_errors(self, op, other_constructor, length):
250-
array = IntervalArray.from_arrays(range(4), range(1, 5))
252+
interval_array = IntervalArray.from_arrays(range(4), range(1, 5))
251253
other = other_constructor([Interval(0, 1)] * length)
252254
with pytest.raises(ValueError, match="Lengths must match to compare"):
253-
op(array, other)
255+
op(interval_array, other)
254256

255257
@pytest.mark.parametrize(
256258
"constructor, expected_type, assert_func",

pandas/tests/arrays/sparse/test_array.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def test_astype_all(self, any_real_dtype):
522522
tm.assert_numpy_array_equal(np.asarray(res.to_dense()), vals.astype(typ))
523523

524524
@pytest.mark.parametrize(
525-
"array, dtype, expected",
525+
"arr, dtype, expected",
526526
[
527527
(
528528
SparseArray([0, 1]),
@@ -557,8 +557,8 @@ def test_astype_all(self, any_real_dtype):
557557
),
558558
],
559559
)
560-
def test_astype_more(self, array, dtype, expected):
561-
result = array.astype(dtype)
560+
def test_astype_more(self, arr, dtype, expected):
561+
result = arr.astype(dtype)
562562
tm.assert_sp_array_equal(result, expected)
563563

564564
def test_astype_nan_raises(self):

pandas/tests/arrays/string_/test_string.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -223,31 +223,31 @@ def test_mul(dtype, request):
223223

224224
@pytest.mark.xfail(reason="GH-28527")
225225
def test_add_strings(dtype):
226-
array = pd.array(["a", "b", "c", "d"], dtype=dtype)
226+
arr = pd.array(["a", "b", "c", "d"], dtype=dtype)
227227
df = pd.DataFrame([["t", "u", "v", "w"]])
228-
assert array.__add__(df) is NotImplemented
228+
assert arr.__add__(df) is NotImplemented
229229

230-
result = array + df
230+
result = arr + df
231231
expected = pd.DataFrame([["at", "bu", "cv", "dw"]]).astype(dtype)
232232
tm.assert_frame_equal(result, expected)
233233

234-
result = df + array
234+
result = df + arr
235235
expected = pd.DataFrame([["ta", "ub", "vc", "wd"]]).astype(dtype)
236236
tm.assert_frame_equal(result, expected)
237237

238238

239239
@pytest.mark.xfail(reason="GH-28527")
240240
def test_add_frame(dtype):
241-
array = pd.array(["a", "b", np.nan, np.nan], dtype=dtype)
241+
arr = pd.array(["a", "b", np.nan, np.nan], dtype=dtype)
242242
df = pd.DataFrame([["x", np.nan, "y", np.nan]])
243243

244-
assert array.__add__(df) is NotImplemented
244+
assert arr.__add__(df) is NotImplemented
245245

246-
result = array + df
246+
result = arr + df
247247
expected = pd.DataFrame([["ax", np.nan, np.nan, np.nan]]).astype(dtype)
248248
tm.assert_frame_equal(result, expected)
249249

250-
result = df + array
250+
result = df + arr
251251
expected = pd.DataFrame([["xa", np.nan, np.nan, np.nan]]).astype(dtype)
252252
tm.assert_frame_equal(result, expected)
253253

pandas/tests/arrays/test_datetimelike.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ def test_strftime_nat(self):
11601160

11611161

11621162
@pytest.mark.parametrize(
1163-
"array,casting_nats",
1163+
"arr,casting_nats",
11641164
[
11651165
(
11661166
TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
@@ -1174,17 +1174,17 @@ def test_strftime_nat(self):
11741174
],
11751175
ids=lambda x: type(x).__name__,
11761176
)
1177-
def test_casting_nat_setitem_array(array, casting_nats):
1178-
expected = type(array)._from_sequence([NaT, array[1], array[2]])
1177+
def test_casting_nat_setitem_array(arr, casting_nats):
1178+
expected = type(arr)._from_sequence([NaT, arr[1], arr[2]])
11791179

11801180
for nat in casting_nats:
1181-
arr = array.copy()
1181+
arr = arr.copy()
11821182
arr[0] = nat
11831183
tm.assert_equal(arr, expected)
11841184

11851185

11861186
@pytest.mark.parametrize(
1187-
"array,non_casting_nats",
1187+
"arr,non_casting_nats",
11881188
[
11891189
(
11901190
TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
@@ -1201,50 +1201,50 @@ def test_casting_nat_setitem_array(array, casting_nats):
12011201
],
12021202
ids=lambda x: type(x).__name__,
12031203
)
1204-
def test_invalid_nat_setitem_array(array, non_casting_nats):
1204+
def test_invalid_nat_setitem_array(arr, non_casting_nats):
12051205
msg = (
12061206
"value should be a '(Timestamp|Timedelta|Period)', 'NaT', or array of those. "
12071207
"Got '(timedelta64|datetime64|int)' instead."
12081208
)
12091209

12101210
for nat in non_casting_nats:
12111211
with pytest.raises(TypeError, match=msg):
1212-
array[0] = nat
1212+
arr[0] = nat
12131213

12141214

12151215
@pytest.mark.parametrize(
1216-
"array",
1216+
"arr",
12171217
[
12181218
pd.date_range("2000", periods=4).array,
12191219
pd.timedelta_range("2000", periods=4).array,
12201220
],
12211221
)
1222-
def test_to_numpy_extra(array):
1222+
def test_to_numpy_extra(arr):
12231223
if np_version_under1p18:
12241224
# np.isnan(NaT) raises, so use pandas'
12251225
isnan = pd.isna
12261226
else:
12271227
isnan = np.isnan
12281228

1229-
array[0] = NaT
1230-
original = array.copy()
1229+
arr[0] = NaT
1230+
original = arr.copy()
12311231

1232-
result = array.to_numpy()
1232+
result = arr.to_numpy()
12331233
assert isnan(result[0])
12341234

1235-
result = array.to_numpy(dtype="int64")
1235+
result = arr.to_numpy(dtype="int64")
12361236
assert result[0] == -9223372036854775808
12371237

1238-
result = array.to_numpy(dtype="int64", na_value=0)
1238+
result = arr.to_numpy(dtype="int64", na_value=0)
12391239
assert result[0] == 0
12401240

1241-
result = array.to_numpy(na_value=array[1].to_numpy())
1241+
result = arr.to_numpy(na_value=arr[1].to_numpy())
12421242
assert result[0] == result[1]
12431243

1244-
result = array.to_numpy(na_value=array[1].to_numpy(copy=False))
1244+
result = arr.to_numpy(na_value=arr[1].to_numpy(copy=False))
12451245
assert result[0] == result[1]
12461246

1247-
tm.assert_equal(array, original)
1247+
tm.assert_equal(arr, original)
12481248

12491249

12501250
@pytest.mark.parametrize("as_index", [True, False])

0 commit comments

Comments
 (0)