Skip to content

Commit 3e8d36b

Browse files
committed
Review (jreback)
1 parent 272da1f commit 3e8d36b

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

pandas/tests/test_strings.py

+42-41
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,27 @@ def test_str_cat(self, box):
164164

165165
# single array
166166
result = s.str.cat()
167-
exp = 'aabbc'
168-
assert result == exp
167+
expected = 'aabbc'
168+
assert result == expected
169169

170170
result = s.str.cat(na_rep='-')
171-
exp = 'aabbc-'
172-
assert result == exp
171+
expected = 'aabbc-'
172+
assert result == expected
173173

174174
result = s.str.cat(sep='_', na_rep='NA')
175-
exp = 'a_a_b_b_c_NA'
176-
assert result == exp
175+
expected = 'a_a_b_b_c_NA'
176+
assert result == expected
177177

178178
t = np.array(['a', np.nan, 'b', 'd', 'foo', np.nan], dtype=object)
179-
exp = box(['aa', 'a-', 'bb', 'bd', 'cfoo', '--'])
179+
expected = box(['aa', 'a-', 'bb', 'bd', 'cfoo', '--'])
180180

181181
# Series/Index with array
182182
result = s.str.cat(t, na_rep='-')
183-
assert_series_or_index_equal(result, exp)
183+
assert_series_or_index_equal(result, expected)
184184

185185
# Series/Index with list
186186
result = s.str.cat(list(t), na_rep='-')
187-
assert_series_or_index_equal(result, exp)
187+
assert_series_or_index_equal(result, expected)
188188

189189
# errors for incorrect lengths
190190
rgx = 'All arrays must be same length, except those having an index.*'
@@ -217,30 +217,30 @@ def test_str_cat_categorical(self, box, dtype_caller, dtype_target):
217217
s = s if box == Index else Series(s, index=s)
218218
t = Index(['b', 'a', 'b', 'c'], dtype=dtype_target)
219219

220-
exp = Index(['ab', 'aa', 'bb', 'ac'])
221-
exp = exp if box == Index else Series(exp, index=s)
220+
expected = Index(['ab', 'aa', 'bb', 'ac'])
221+
expected = expected if box == Index else Series(expected, index=s)
222222

223223
# Series/Index with unaligned Index
224224
with tm.assert_produces_warning(expected_warning=FutureWarning):
225225
# FutureWarning to switch to alignment by default
226226
result = s.str.cat(t)
227-
assert_series_or_index_equal(result, exp)
227+
assert_series_or_index_equal(result, expected)
228228

229229
# Series/Index with Series having matching Index
230230
t = Series(t, index=s)
231231
result = s.str.cat(t)
232-
assert_series_or_index_equal(result, exp)
232+
assert_series_or_index_equal(result, expected)
233233

234234
# Series/Index with Series.values
235235
result = s.str.cat(t.values)
236-
assert_series_or_index_equal(result, exp)
236+
assert_series_or_index_equal(result, expected)
237237

238238
# Series/Index with Series having different Index
239239
t = Series(t.values, index=t)
240240
with tm.assert_produces_warning(expected_warning=FutureWarning):
241241
# FutureWarning to switch to alignment by default
242242
result = s.str.cat(t)
243-
assert_series_or_index_equal(result, exp)
243+
assert_series_or_index_equal(result, expected)
244244

245245
@pytest.mark.parametrize('box', [Series, Index])
246246
def test_str_cat_mixed_inputs(self, box):
@@ -250,56 +250,57 @@ def test_str_cat_mixed_inputs(self, box):
250250
t = Series(['A', 'B', 'C', 'D'], index=s.values)
251251
d = concat([t, Series(s, index=s)], axis=1)
252252

253-
exp = Index(['aAa', 'bBb', 'cCc', 'dDd'])
254-
exp = exp if box == Index else Series(exp.values, index=s.values)
253+
expected = Index(['aAa', 'bBb', 'cCc', 'dDd'])
254+
expected = expected if box == Index else Series(expected.values,
255+
index=s.values)
255256

256257
# Series/Index with DataFrame
257258
result = s.str.cat(d)
258-
assert_series_or_index_equal(result, exp)
259+
assert_series_or_index_equal(result, expected)
259260

260261
# Series/Index with two-dimensional ndarray
261262
result = s.str.cat(d.values)
262-
assert_series_or_index_equal(result, exp)
263+
assert_series_or_index_equal(result, expected)
263264

264265
# Series/Index with list of Series
265266
result = s.str.cat([t, s])
266-
assert_series_or_index_equal(result, exp)
267+
assert_series_or_index_equal(result, expected)
267268

268269
# Series/Index with mixed list of Series/array
269270
result = s.str.cat([t, s.values])
270-
assert_series_or_index_equal(result, exp)
271+
assert_series_or_index_equal(result, expected)
271272

272273
# Series/Index with list of list-likes
273274
with tm.assert_produces_warning(expected_warning=FutureWarning):
274275
# nested list-likes will be deprecated
275276
result = s.str.cat([t.values, list(s)])
276-
assert_series_or_index_equal(result, exp)
277+
assert_series_or_index_equal(result, expected)
277278

278279
# Series/Index with list of Series; different indexes
279280
t.index = ['b', 'c', 'd', 'a']
280281
with tm.assert_produces_warning(expected_warning=FutureWarning):
281282
# FutureWarning to switch to alignment by default
282283
result = s.str.cat([t, s])
283-
assert_series_or_index_equal(result, exp)
284+
assert_series_or_index_equal(result, expected)
284285

285286
# Series/Index with mixed list; different indexes
286287
with tm.assert_produces_warning(expected_warning=FutureWarning):
287288
# FutureWarning to switch to alignment by default
288289
result = s.str.cat([t, s.values])
289-
assert_series_or_index_equal(result, exp)
290+
assert_series_or_index_equal(result, expected)
290291

291292
# Series/Index with DataFrame; different indexes
292293
d.index = ['b', 'c', 'd', 'a']
293294
with tm.assert_produces_warning(expected_warning=FutureWarning):
294295
# FutureWarning to switch to alignment by default
295296
result = s.str.cat(d)
296-
assert_series_or_index_equal(result, exp)
297+
assert_series_or_index_equal(result, expected)
297298

298299
# Series/Index with iterator of list-likes
299300
with tm.assert_produces_warning(expected_warning=FutureWarning):
300301
# nested list-likes will be deprecated
301302
result = s.str.cat(iter([t.values, list(s)]))
302-
assert_series_or_index_equal(result, exp)
303+
assert_series_or_index_equal(result, expected)
303304

304305
# errors for incorrect lengths
305306
rgx = 'All arrays must be same length, except those having an index.*'
@@ -359,47 +360,47 @@ def test_str_cat_align_indexed(self, box, join):
359360
t = Series(['D', 'A', 'E', 'B'], index=['d', 'a', 'e', 'b'])
360361
sa, ta = s.align(t, join=join)
361362
# result after manual alignment of inputs
362-
exp = sa.str.cat(ta, na_rep='-')
363+
expected = sa.str.cat(ta, na_rep='-')
363364

364365
if box == Index:
365366
s = Index(s)
366367
sa = Index(sa)
367-
exp = Index(exp)
368+
expected = Index(expected)
368369

369370
result = s.str.cat(t, join=join, na_rep='-')
370-
assert_series_or_index_equal(result, exp)
371+
assert_series_or_index_equal(result, expected)
371372

372373
@pytest.mark.parametrize('join', ['left', 'outer', 'inner', 'right'])
373374
def test_str_cat_align_mixed_inputs(self, join):
374375
s = Series(['a', 'b', 'c', 'd'])
375376
t = Series(['d', 'a', 'e', 'b'], index=[3, 0, 4, 1])
376377
d = concat([t, t], axis=1)
377378

378-
exp_outer = Series(['aaa', 'bbb', 'c--', 'ddd', '-ee'])
379-
exp = exp_outer.loc[s.index.join(t.index, how=join)]
379+
expected_outer = Series(['aaa', 'bbb', 'c--', 'ddd', '-ee'])
380+
expected = expected_outer.loc[s.index.join(t.index, how=join)]
380381

381382
# list of Series
382383
result = s.str.cat([t, t], join=join, na_rep='-')
383-
tm.assert_series_equal(result, exp)
384+
tm.assert_series_equal(result, expected)
384385

385386
# DataFrame
386387
result = s.str.cat(d, join=join, na_rep='-')
387-
tm.assert_series_equal(result, exp)
388+
tm.assert_series_equal(result, expected)
388389

389390
# mixed list of indexed/unindexed
390391
u = np.array(['A', 'B', 'C', 'D'])
391-
exp_outer = Series(['aaA', 'bbB', 'c-C', 'ddD', '-e-'])
392+
expected_outer = Series(['aaA', 'bbB', 'c-C', 'ddD', '-e-'])
392393
# joint index of rhs [t, u]; u will be forced have index of s
393394
rhs_idx = t.index & s.index if join == 'inner' else t.index | s.index
394395

395-
exp = exp_outer.loc[s.index.join(rhs_idx, how=join)]
396+
expected = expected_outer.loc[s.index.join(rhs_idx, how=join)]
396397
result = s.str.cat([t, u], join=join, na_rep='-')
397-
tm.assert_series_equal(result, exp)
398+
tm.assert_series_equal(result, expected)
398399

399400
with tm.assert_produces_warning(expected_warning=FutureWarning):
400401
# nested list-likes will be deprecated
401402
result = s.str.cat([t, list(u)], join=join, na_rep='-')
402-
tm.assert_series_equal(result, exp)
403+
tm.assert_series_equal(result, expected)
403404

404405
# errors for incorrect lengths
405406
rgx = 'If `others` contains arrays or lists \(or other list-likes.*'
@@ -418,14 +419,14 @@ def test_str_cat_special_cases(self):
418419
t = Series(['d', 'a', 'e', 'b'], index=[3, 0, 4, 1])
419420

420421
# iterator of elements with different types
421-
exp = Series(['aaa', 'bbb', 'c-c', 'ddd', '-e-'])
422+
expected = Series(['aaa', 'bbb', 'c-c', 'ddd', '-e-'])
422423
result = s.str.cat(iter([t, s.values]), join='outer', na_rep='-')
423-
tm.assert_series_equal(result, exp)
424+
tm.assert_series_equal(result, expected)
424425

425426
# right-align with different indexes in others
426-
exp = Series(['aa-', 'd-d'], index=[0, 3])
427+
expected = Series(['aa-', 'd-d'], index=[0, 3])
427428
result = s.str.cat([t.loc[[0]], t.loc[[3]]], join='right', na_rep='-')
428-
tm.assert_series_equal(result, exp)
429+
tm.assert_series_equal(result, expected)
429430

430431
def test_cat_on_filtered_index(self):
431432
df = DataFrame(index=MultiIndex.from_product(

0 commit comments

Comments
 (0)