Skip to content

Commit a738e68

Browse files
committed
Adjust more tests
1 parent d0ed329 commit a738e68

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

pandas/tests/extension/base/dim2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def test_frame_from_2d_array(self, data):
4242
arr2d = data.repeat(2).reshape(-1, 2)
4343

4444
df = pd.DataFrame(arr2d)
45-
expected = pd.DataFrame({0: arr2d[:, 0], 1: arr2d[:, 1]})
45+
expected = pd.DataFrame(
46+
{0: arr2d[:, 0], 1: arr2d[:, 1]}, columns=pd.RangeIndex(2)
47+
)
4648
tm.assert_frame_equal(df, expected)
4749

4850
def test_swapaxes(self, data):

pandas/tests/frame/methods/test_quantile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_axis_numeric_only_true(self, interp_method):
127127
result = df.quantile(
128128
0.5, axis=1, numeric_only=True, interpolation=interpolation, method=method
129129
)
130-
expected = Series([3.0, 4.0], index=[0, 1], name=0.5)
130+
expected = Series([3.0, 4.0], index=range(2), name=0.5)
131131
if interpolation == "nearest":
132132
expected = expected.astype(np.int64)
133133
tm.assert_series_equal(result, expected)

pandas/tests/frame/test_reductions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,8 @@ def test_nunique(self):
490490
tm.assert_series_equal(
491491
df.nunique(dropna=False), Series({"A": 1, "B": 3, "C": 3})
492492
)
493-
tm.assert_series_equal(df.nunique(axis=1), Series({0: 1, 1: 2, 2: 2}))
494-
tm.assert_series_equal(
495-
df.nunique(axis=1, dropna=False), Series({0: 1, 1: 3, 2: 2})
496-
)
493+
tm.assert_series_equal(df.nunique(axis=1), Series([1, 2, 2]))
494+
tm.assert_series_equal(df.nunique(axis=1, dropna=False), Series([1, 3, 2]))
497495

498496
@pytest.mark.parametrize("tz", [None, "UTC"])
499497
def test_mean_mixed_datetime_numeric(self, tz):

pandas/tests/io/excel/test_writers.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ def test_multiindex_interval_datetimes(self, tmp_excel):
339339
],
340340
]
341341
),
342+
columns=Index([0]),
342343
)
343344
tm.assert_frame_equal(result, expected)
344345

@@ -384,7 +385,10 @@ def test_excel_sheet_size(self, tmp_excel):
384385
col_df.to_excel(tmp_excel)
385386

386387
def test_excel_sheet_by_name_raise(self, tmp_excel):
387-
gt = DataFrame(np.random.default_rng(2).standard_normal((10, 2)))
388+
gt = DataFrame(
389+
np.random.default_rng(2).standard_normal((10, 2)),
390+
index=Index(list(range(10))),
391+
)
388392
gt.to_excel(tmp_excel)
389393

390394
with ExcelFile(tmp_excel) as xl:
@@ -505,7 +509,9 @@ def test_int_types(self, np_type, tmp_excel):
505509
# Test np.int values read come back as int
506510
# (rather than float which is Excel's format).
507511
df = DataFrame(
508-
np.random.default_rng(2).integers(-10, 10, size=(10, 2)), dtype=np_type
512+
np.random.default_rng(2).integers(-10, 10, size=(10, 2)),
513+
dtype=np_type,
514+
index=Index(list(range(10))),
509515
)
510516
df.to_excel(tmp_excel, sheet_name="test1")
511517

@@ -521,7 +527,11 @@ def test_int_types(self, np_type, tmp_excel):
521527
@pytest.mark.parametrize("np_type", [np.float16, np.float32, np.float64])
522528
def test_float_types(self, np_type, tmp_excel):
523529
# Test np.float values read come back as float.
524-
df = DataFrame(np.random.default_rng(2).random(10), dtype=np_type)
530+
df = DataFrame(
531+
np.random.default_rng(2).random(10),
532+
dtype=np_type,
533+
index=Index(list(range(10))),
534+
)
525535
df.to_excel(tmp_excel, sheet_name="test1")
526536

527537
with ExcelFile(tmp_excel) as reader:
@@ -533,7 +543,7 @@ def test_float_types(self, np_type, tmp_excel):
533543

534544
def test_bool_types(self, tmp_excel):
535545
# Test np.bool_ values read come back as float.
536-
df = DataFrame([1, 0, True, False], dtype=np.bool_)
546+
df = DataFrame([1, 0, True, False], dtype=np.bool_, index=Index(list(range(4))))
537547
df.to_excel(tmp_excel, sheet_name="test1")
538548

539549
with ExcelFile(tmp_excel) as reader:
@@ -544,7 +554,7 @@ def test_bool_types(self, tmp_excel):
544554
tm.assert_frame_equal(df, recons)
545555

546556
def test_inf_roundtrip(self, tmp_excel):
547-
df = DataFrame([(1, np.inf), (2, 3), (5, -np.inf)])
557+
df = DataFrame([(1, np.inf), (2, 3), (5, -np.inf)], index=Index(list(range(3))))
548558
df.to_excel(tmp_excel, sheet_name="test1")
549559

550560
with ExcelFile(tmp_excel) as reader:
@@ -640,7 +650,13 @@ def test_roundtrip_indexlabels(self, merge_cells, frame, tmp_excel):
640650
df.index.names = ["test"]
641651
assert df.index.names == recons.index.names
642652

643-
df = DataFrame(np.random.default_rng(2).standard_normal((10, 2))) >= 0
653+
df = (
654+
DataFrame(
655+
np.random.default_rng(2).standard_normal((10, 2)),
656+
index=Index(list(range(10))),
657+
)
658+
>= 0
659+
)
644660
df.to_excel(
645661
tmp_excel, sheet_name="test1", index_label="test", merge_cells=merge_cells
646662
)

0 commit comments

Comments
 (0)