Skip to content

Commit 10ce090

Browse files
committed
Merge branch 'ref/index_equiv' of https://github.com/mroeschke/pandas into ref/index_equiv
2 parents b89b9d4 + 4df0b7b commit 10ce090

File tree

9 files changed

+36
-30
lines changed

9 files changed

+36
-30
lines changed

pandas/tests/frame/methods/test_compare.py

Lines changed: 5 additions & 4 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]],
@@ -60,7 +60,7 @@ def test_compare_various_formats(keep_shape, keep_equal):
6060
result = df.compare(df2, keep_shape=keep_shape, keep_equal=keep_equal)
6161

6262
if keep_shape:
63-
indices = pd.Index([0, 1, 2])
63+
indices = pd.RangeIndex(3)
6464
columns = pd.MultiIndex.from_product(
6565
[["col1", "col2", "col3"], ["self", "other"]]
6666
)
@@ -85,7 +85,7 @@ def test_compare_various_formats(keep_shape, keep_equal):
8585
columns=columns,
8686
)
8787
else:
88-
indices = pd.Index([0, 2])
88+
indices = pd.RangeIndex(0, 4, 2)
8989
columns = pd.MultiIndex.from_product([["col1", "col3"], ["self", "other"]])
9090
expected = pd.DataFrame(
9191
[["a", "c", 1.0, 1.0], ["c", "c", 3.0, 4.0]], index=indices, columns=columns
@@ -203,6 +203,7 @@ def test_compare_result_names():
203203
},
204204
)
205205
result = df1.compare(df2, result_names=("left", "right"))
206+
result.index = pd.Index([0, 2])
206207
expected = pd.DataFrame(
207208
{
208209
("col1", "left"): {0: "a", 2: np.nan},

pandas/tests/frame/methods/test_drop_duplicates.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,15 @@ def test_drop_duplicates_inplace():
411411
@pytest.mark.parametrize(
412412
"origin_dict, output_dict, ignore_index, output_index",
413413
[
414-
({"A": [2, 2, 3]}, {"A": [2, 3]}, True, [0, 1]),
415-
({"A": [2, 2, 3]}, {"A": [2, 3]}, False, [0, 2]),
416-
({"A": [2, 2, 3], "B": [2, 2, 4]}, {"A": [2, 3], "B": [2, 4]}, True, [0, 1]),
417-
({"A": [2, 2, 3], "B": [2, 2, 4]}, {"A": [2, 3], "B": [2, 4]}, False, [0, 2]),
414+
({"A": [2, 2, 3]}, {"A": [2, 3]}, True, range(2)),
415+
({"A": [2, 2, 3]}, {"A": [2, 3]}, False, range(0, 4, 2)),
416+
({"A": [2, 2, 3], "B": [2, 2, 4]}, {"A": [2, 3], "B": [2, 4]}, True, range(2)),
417+
(
418+
{"A": [2, 2, 3], "B": [2, 2, 4]},
419+
{"A": [2, 3], "B": [2, 4]},
420+
False,
421+
range(0, 4, 2),
422+
),
418423
],
419424
)
420425
def test_drop_duplicates_ignore_index(

pandas/tests/frame/methods/test_dropna.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_dropna_tz_aware_datetime(self):
195195
# Ex2
196196
df = DataFrame({"Time": [dt1, None, np.nan, dt2]})
197197
result = df.dropna(axis=0)
198-
expected = DataFrame([dt1, dt2], columns=["Time"], index=[0, 3])
198+
expected = DataFrame([dt1, dt2], columns=["Time"], index=range(0, 6, 3))
199199
tm.assert_frame_equal(result, expected)
200200

201201
def test_dropna_categorical_interval_index(self):
@@ -233,7 +233,7 @@ def test_set_single_column_subset(self):
233233
# GH 41021
234234
df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.nan, 5]})
235235
expected = DataFrame(
236-
{"A": [1, 3], "B": list("ac"), "C": [4.0, 5.0]}, index=[0, 2]
236+
{"A": [1, 3], "B": list("ac"), "C": [4.0, 5.0]}, index=range(0, 4, 2)
237237
)
238238
result = df.dropna(subset="C")
239239
tm.assert_frame_equal(result, expected)

pandas/tests/frame/methods/test_explode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_ignore_index():
210210
df = pd.DataFrame({"id": range(0, 20, 10), "values": [list("ab"), list("cd")]})
211211
result = df.explode("values", ignore_index=True)
212212
expected = pd.DataFrame(
213-
{"id": [0, 0, 10, 10], "values": list("abcd")}, index=[0, 1, 2, 3]
213+
{"id": [0, 0, 10, 10], "values": list("abcd")}, index=range(4)
214214
)
215215
tm.assert_frame_equal(result, expected)
216216

pandas/tests/frame/methods/test_transpose.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_transpose_td64_intervals(self):
2525
df = DataFrame(ii)
2626

2727
result = df.T
28+
result.columns = Index(list(range(len(ii))))
2829
expected = DataFrame({i: ii[i : i + 1] for i in range(len(ii))})
2930
tm.assert_frame_equal(result, expected)
3031

@@ -153,7 +154,6 @@ def test_transpose_not_inferring_dt(self):
153154
result = df.T
154155
expected = DataFrame(
155156
[[Timestamp("2019-12-31"), Timestamp("2019-12-31")]],
156-
columns=[0, 1],
157157
index=["a"],
158158
dtype=object,
159159
)
@@ -175,7 +175,6 @@ def test_transpose_not_inferring_dt_mixed_blocks(self):
175175
[Timestamp("2019-12-31"), Timestamp("2019-12-31")],
176176
[Timestamp("2019-12-31"), Timestamp("2019-12-31")],
177177
],
178-
columns=[0, 1],
179178
index=["a", "b"],
180179
dtype=object,
181180
)

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/indexes/numeric/test_setops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_intersection(self):
4141

4242
other = Index([1, 2, 3, 4, 5])
4343
result = index.intersection(other)
44-
expected = Index(np.sort(np.intersect1d(index.values, other.values)))
44+
expected = Index(range(1, 5))
4545
tm.assert_index_equal(result, expected)
4646

4747
result = other.intersection(index)

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

pandas/tests/test_sorting.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def test_int64_overflow_how_merge(self, left_right, join_type):
221221

222222
out = merge(left, right, how="outer")
223223
out.sort_values(out.columns.tolist(), inplace=True)
224-
out.index = np.arange(len(out))
225224
tm.assert_frame_equal(out, merge(left, right, how=join_type, sort=True))
226225

227226
@pytest.mark.slow

0 commit comments

Comments
 (0)