diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 4aefb73bf912c..1d2208592a06d 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -307,9 +307,8 @@ def test_groupby_levels_and_columns(self): # reset_index changes columns dtype to object by_columns = df.reset_index().groupby(idx_names).mean() - tm.assert_frame_equal(by_levels, by_columns, check_column_type=False) - - by_columns.columns = Index(by_columns.columns, dtype=np.int64) + # without casting, by_columns.columns is object-dtype + by_columns.columns = by_columns.columns.astype(np.int64) tm.assert_frame_equal(by_levels, by_columns) def test_groupby_categorical_index_and_columns(self, observed): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index cf6c2878acd9a..f6aa2371cf13a 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1782,21 +1782,23 @@ def test_series_getitem_label_list_missing_integer_values(): @pytest.mark.parametrize( - "columns, column_key, expected_columns, check_column_type", + "columns, column_key, expected_columns", [ - ([2011, 2012, 2013], [2011, 2012], [0, 1], True), - ([2011, 2012, "All"], [2011, 2012], [0, 1], False), - ([2011, 2012, "All"], [2011, "All"], [0, 2], True), + ([2011, 2012, 2013], [2011, 2012], [0, 1]), + ([2011, 2012, "All"], [2011, 2012], [0, 1]), + ([2011, 2012, "All"], [2011, "All"], [0, 2]), ], ) -def test_loc_getitem_label_list_integer_labels( - columns, column_key, expected_columns, check_column_type -): +def test_loc_getitem_label_list_integer_labels(columns, column_key, expected_columns): # gh-14836 df = DataFrame(np.random.rand(3, 3), columns=columns, index=list("ABC")) expected = df.iloc[:, expected_columns] result = df.loc[["A", "B", "C"], column_key] - tm.assert_frame_equal(result, expected, check_column_type=check_column_type) + + if df.columns.is_object() and all(isinstance(x, int) for x in column_key): + expected.columns = expected.columns.astype(int) + + tm.assert_frame_equal(result, expected, check_column_type=True) def test_loc_setitem_float_intindex(): diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index f15a64947d83d..80ebeb4c03d89 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -472,12 +472,12 @@ def test_int_types(self, np_type, path): # Test with convert_float=False comes back as float. float_frame = df.astype(float) + float_frame.columns = float_frame.columns.astype(float) + float_frame.index = float_frame.index.astype(float) recons = pd.read_excel( path, sheet_name="test1", convert_float=False, index_col=0 ) - tm.assert_frame_equal( - recons, float_frame, check_index_type=False, check_column_type=False - ) + tm.assert_frame_equal(recons, float_frame) @pytest.mark.parametrize("np_type", [np.float16, np.float32, np.float64]) def test_float_types(self, np_type, path): diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 7a5aca13b33f5..ce95eb59ed3c4 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -727,9 +727,7 @@ def test_series_with_dtype_datetime(self, dtype, expected): def test_frame_from_json_precise_float(self): df = DataFrame([[4.56, 4.56, 4.56], [4.56, 4.56, 4.56]]) result = read_json(df.to_json(), precise_float=True) - tm.assert_frame_equal( - result, df, check_index_type=False, check_column_type=False - ) + tm.assert_frame_equal(result, df) def test_typ(self): diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index afd2f56efb935..a63a98cf9858b 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -1631,16 +1631,12 @@ def check_col(key, name, size): & (df_new.A > 0) & (df_new.B < 0) ] - tm.assert_frame_equal( - result, expected, check_index_type=False, check_freq=False - ) + tm.assert_frame_equal(result, expected) # yield an empty frame result = store.select("df", "string='foo' and string2='cool'") expected = df_new[(df_new.string == "foo") & (df_new.string2 == "cool")] - tm.assert_frame_equal( - result, expected, check_index_type=False, check_freq=False - ) + tm.assert_frame_equal(result, expected) with ensure_clean_store(setup_path) as store: # doc example @@ -1660,16 +1656,11 @@ def check_col(key, name, size): result = store.select("df_dc", "B>0") expected = df_dc[df_dc.B > 0] - tm.assert_frame_equal( - result, expected, check_index_type=False, check_freq=False - ) + tm.assert_frame_equal(result, expected) result = store.select("df_dc", ["B > 0", "C > 0", "string == foo"]) expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == "foo")] - tm.assert_frame_equal( - result, expected, check_index_type=False, check_freq=False - ) - # FIXME: 2020-05-07 freq check randomly fails in the CI + tm.assert_frame_equal(result, expected) with ensure_clean_store(setup_path) as store: # doc example part 2 @@ -2374,9 +2365,7 @@ def test_series(self, setup_path): ts3 = Series( ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object) ) - self._check_roundtrip( - ts3, tm.assert_series_equal, path=setup_path, check_index_type=False - ) + self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path) def test_float_index(self, setup_path):