Skip to content

TST: tighten testing assertions #38223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 10 additions & 8 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
21 changes: 5 additions & 16 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):

Expand Down