Skip to content

Commit fb5a6fe

Browse files
committed
Fix more tests
1 parent e6a8eb2 commit fb5a6fe

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

pandas/tests/frame/methods/test_compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def test_compare_axis(align_axis):
2121
result = df.compare(df2, align_axis=align_axis)
2222

2323
if align_axis in (1, "columns"):
24-
indices = pd.Index([0, 2])
24+
indices = pd.RangeIndex(0, 4, 2)
2525
columns = pd.MultiIndex.from_product([["col1", "col3"], ["self", "other"]])
2626
expected = pd.DataFrame(
2727
[["a", "c", np.nan, np.nan], [np.nan, np.nan, 3.0, 4.0]],
2828
index=indices,
2929
columns=columns,
3030
)
3131
else:
32-
indices = pd.MultiIndex.from_product([[0, 2], ["self", "other"]])
32+
indices = pd.MultiIndex.from_product([range(0, 4, 2), ["self", "other"]])
3333
columns = pd.Index(["col1", "col3"])
3434
expected = pd.DataFrame(
3535
[["a", np.nan], ["c", np.nan], [np.nan, 3.0], [np.nan, 4.0]],

pandas/tests/groupby/test_filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_filter_using_len():
242242
actual = grouped.filter(lambda x: len(x) > 2)
243243
expected = DataFrame(
244244
{"A": np.arange(2, 6), "B": list("bbbb"), "C": np.arange(2, 6)},
245-
index=np.arange(2, 6, dtype=np.int64),
245+
index=range(2, 6),
246246
)
247247
tm.assert_frame_equal(actual, expected)
248248

@@ -254,7 +254,7 @@ def test_filter_using_len():
254254
s = df["B"]
255255
grouped = s.groupby(s)
256256
actual = grouped.filter(lambda x: len(x) > 2)
257-
expected = Series(4 * ["b"], index=np.arange(2, 6, dtype=np.int64), name="B")
257+
expected = Series(4 * ["b"], index=range(2, 6), name="B")
258258
tm.assert_series_equal(actual, expected)
259259

260260
actual = grouped.filter(lambda x: len(x) > 4)

pandas/tests/series/methods/test_reindex.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,15 @@ def test_reindex_categorical():
234234
tm.assert_series_equal(result, expected)
235235

236236
# partial reindexing
237-
expected = Series(Categorical(values=["b", "c"], categories=["a", "b", "c"]))
238-
expected.index = [1, 2]
237+
expected = Series(
238+
Categorical(values=["b", "c"], categories=["a", "b", "c"]), index=range(1, 3)
239+
)
239240
result = s.reindex([1, 2])
240241
tm.assert_series_equal(result, expected)
241242

242-
expected = Series(Categorical(values=["c", np.nan], categories=["a", "b", "c"]))
243-
expected.index = [2, 3]
243+
expected = Series(
244+
Categorical(values=["c", np.nan], categories=["a", "b", "c"]), index=range(2, 4)
245+
)
244246
result = s.reindex([2, 3])
245247
tm.assert_series_equal(result, expected)
246248

@@ -261,24 +263,24 @@ def test_reindex_fill_value():
261263
# floats
262264
floats = Series([1.0, 2.0, 3.0])
263265
result = floats.reindex([1, 2, 3])
264-
expected = Series([2.0, 3.0, np.nan], index=[1, 2, 3])
266+
expected = Series([2.0, 3.0, np.nan], index=range(1, 4))
265267
tm.assert_series_equal(result, expected)
266268

267269
result = floats.reindex([1, 2, 3], fill_value=0)
268-
expected = Series([2.0, 3.0, 0], index=[1, 2, 3])
270+
expected = Series([2.0, 3.0, 0], index=range(1, 4))
269271
tm.assert_series_equal(result, expected)
270272

271273
# -----------------------------------------------------------
272274
# ints
273275
ints = Series([1, 2, 3])
274276

275277
result = ints.reindex([1, 2, 3])
276-
expected = Series([2.0, 3.0, np.nan], index=[1, 2, 3])
278+
expected = Series([2.0, 3.0, np.nan], index=range(1, 4))
277279
tm.assert_series_equal(result, expected)
278280

279281
# don't upcast
280282
result = ints.reindex([1, 2, 3], fill_value=0)
281-
expected = Series([2, 3, 0], index=[1, 2, 3])
283+
expected = Series([2, 3, 0], index=range(1, 4))
282284
assert issubclass(result.dtype.type, np.integer)
283285
tm.assert_series_equal(result, expected)
284286

@@ -287,23 +289,23 @@ def test_reindex_fill_value():
287289
objects = Series([1, 2, 3], dtype=object)
288290

289291
result = objects.reindex([1, 2, 3])
290-
expected = Series([2, 3, np.nan], index=[1, 2, 3], dtype=object)
292+
expected = Series([2, 3, np.nan], index=range(1, 4), dtype=object)
291293
tm.assert_series_equal(result, expected)
292294

293295
result = objects.reindex([1, 2, 3], fill_value="foo")
294-
expected = Series([2, 3, "foo"], index=[1, 2, 3], dtype=object)
296+
expected = Series([2, 3, "foo"], index=range(1, 4), dtype=object)
295297
tm.assert_series_equal(result, expected)
296298

297299
# ------------------------------------------------------------
298300
# bools
299301
bools = Series([True, False, True])
300302

301303
result = bools.reindex([1, 2, 3])
302-
expected = Series([False, True, np.nan], index=[1, 2, 3], dtype=object)
304+
expected = Series([False, True, np.nan], index=range(1, 4), dtype=object)
303305
tm.assert_series_equal(result, expected)
304306

305307
result = bools.reindex([1, 2, 3], fill_value=False)
306-
expected = Series([False, True, False], index=[1, 2, 3])
308+
expected = Series([False, True, False], index=range(1, 4))
307309
tm.assert_series_equal(result, expected)
308310

309311

@@ -318,7 +320,7 @@ def test_reindex_fill_value_datetimelike_upcast(dtype, fill_value):
318320
ser = Series([NaT], dtype=dtype)
319321

320322
result = ser.reindex([0, 1], fill_value=fill_value)
321-
expected = Series([NaT, fill_value], index=[0, 1], dtype=object)
323+
expected = Series([NaT, fill_value], index=range(2), dtype=object)
322324
tm.assert_series_equal(result, expected)
323325

324326

0 commit comments

Comments
 (0)