Skip to content

CLN: remove need for assert_matching in pandas/tests/indexes/test_multi.py #19105

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

Open
jreback opened this issue Jan 6, 2018 · 5 comments
Open
Labels
Clean MultiIndex Testing pandas testing functions or related to the test suite

Comments

@jreback
Copy link
Contributor

jreback commented Jan 6, 2018

xref #19058

I believe this can be subsumed with simple result.equals(expected) index comparisions.
no need to have a non-standard comparison method.

@jreback jreback added this to the Next Major Release milestone Jan 6, 2018
@jreback
Copy link
Contributor Author

jreback commented Jan 6, 2018

cc @Mofef

@databasedav
Copy link
Contributor

Index.equals uses:

def array_equivalent(left, right, strict_nan=False):
"""
True if two arrays, left and right, have equal non-NaN elements, and NaNs
in corresponding locations. False otherwise. It is assumed that left and
right are NumPy arrays of the same dtype. The behavior of this function
(particularly with respect to NaNs) is not defined if the dtypes are
different.

which assumes that the dtypes of each array is the same whereas some of the assert_matching calls in test_multi.py specify the checking of dtypes. Should I add an argument for checking dtypes in Index.equals?

@jreback
Copy link
Contributor Author

jreback commented Jan 7, 2018

oh sorry, I meant to say tm.assert_index_equals which does full comparisons.

@databasedav
Copy link
Contributor

Ok so all of the assert_matching's are comparing .level's and .label's

def test_set_levels(self):
# side note - you probably wouldn't want to use levels and labels
# directly like this - but it is possible.
levels = self.index.levels
new_levels = [[lev + 'a' for lev in level] for level in levels]
def assert_matching(actual, expected, check_dtype=False):
# avoid specifying internal representation
# as much as possible
assert len(actual) == len(expected)
for act, exp in zip(actual, expected):
act = np.asarray(act)
exp = np.asarray(exp)
tm.assert_numpy_array_equal(act, exp, check_dtype=check_dtype)
# level changing [w/o mutation]
ind2 = self.index.set_levels(new_levels)
assert_matching(ind2.levels, new_levels)
assert_matching(self.index.levels, levels)

In the first test, a slightly modified levels new_levels is being set on a new index ind2 and then assert_matching is checking if ind2's levels have been set correctly without mutating the original. So does using tm.assert_index_equal make sense in this case since it would require manually creating a new index to compare levels when all we want to compare are the levels themselves?

@jreback
Copy link
Contributor Author

jreback commented Jan 9, 2018

I prefer to use the stock routines rather than write a custom routine.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Jun 12, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean MultiIndex Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

4 participants