Skip to content
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

TST: fix tests for mixed int string index #55458

Closed
wants to merge 23 commits into from

Conversation

natmokval
Copy link
Contributor

"mixed-int-string": Index([0, "a", 1, "b", 2, "c"])

Adding "mixed-int-string" causes some tests to fail, fixed these tests.

@natmokval natmokval changed the title Tst mixed int string index TST: fix tests for mixed int string index Oct 9, 2023
@natmokval natmokval marked this pull request as ready for review October 10, 2023 08:26
@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Oct 10, 2023
try:
indexer = non_nan_idx[non_nans.argsort(kind=kind)]
except TypeError as err:
msg = "'<' not supported between "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like the message just cuts off? what is the message in err?

Copy link
Contributor Author

@natmokval natmokval Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comments.
Yes, I cut the message off because in tests I had both: "'<' not supported between instances of 'int' and 'str'" and "'<' not supported between instances of 'str' and 'int'" and sometimes messages did not match.
I corrected error message in the function nargsort and tests, now all error messages match.

@@ -151,6 +151,15 @@ def test_searchsorted(request, index_or_series_obj):
# comparison semantics https://github.com/numpy/numpy/issues/15981
mark = pytest.mark.xfail(reason="complex objects are not comparable")
request.node.add_marker(mark)
elif any(isinstance(elem, int) for elem in obj.values[:]) and any(
isinstance(elem, str) for elem in obj.values[:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a pretty awkward check. maybe just check obj[0] and obj[1] with a comment the check is written with the mixed-int-string entry in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, I replaced the check with tm.assert_mixed_int_string_entry

expected = index[1:].set_names(expected_name).sort_values()
tm.assert_index_equal(intersect, expected)
if (
len(index.values) > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a tm.check_for_this_case to de-duplicate all these? or just a new fixture that specifically excludes the relevant case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, I added tm.assert_mixed_int_string_entry and replaced the checks with it.

@natmokval
Copy link
Contributor Author

@jbrockmendel, I corrected my PR, could you please take a look at the update?

Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Nov 16, 2023
@natmokval
Copy link
Contributor Author

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

Yes, this PR is still actual.

@natmokval
Copy link
Contributor Author

@jbrockmendel, I updated my PR, could you please take a look at the update?

@mroeschke mroeschke removed the Stale label Nov 28, 2023
try:
indexer = non_nan_idx[non_nans.argsort(kind=kind)]
except TypeError as err:
msg = "'<' not supported between instances of 'int' and 'str'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there cases other than this particular test case that might hit this?

@@ -1382,3 +1382,20 @@ def assert_metadata_equivalent(
assert val is None
else:
assert val == getattr(right, attr, None)


def assert_mixed_int_string_entry(arr) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "is_mixed_..." instead of "assert_mixed_..."?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I replaced assert_mixed_int_string_entry with is_mixed_int_string_entry.


def assert_mixed_int_string_entry(arr) -> bool:
"""
Check that arr is mixed-int-string entry.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be clearer if it refers directly to the relevant fixture.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is an instance of a more general pain point in test writing:

def test_something(fixture):
    if the_fixture_value_is_this_particular_entry(fixture):
        ...

usually we either inspect the object like this assert_mixed_int_string_entry is doing or in some cases we pass request and do something hacky with request.fixturenames or something. I wonder if there is a recommended pattern for like pytest.get_active_fixture_id("index") that would return "mixed-int-string" here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I coud't find a recommended pattern that would return "mixed-int-string" in this case.
Instead I passed request and used request.node.callspec.id to return "mixed-int-string".

Now I inspect the object by using request.node.callspec.id instead of is_mixed_int_string_entry. The function is_mixed_int_string_entry is removed.
Sorry it took so long. Could you please take a look at this PR?

@natmokval
Copy link
Contributor Author

I added an entry: "mixed-int-string" in conftest's indices_dict and corrected tests, ci - green. @MarcoGorelli could you please take a look at this PR?

@natmokval
Copy link
Contributor Author

gentle ping @jbrockmendel

@mroeschke
Copy link
Member

Looks like this PR has gone stale and has conflicts now. Closing to clear the queue but if interested in contributing please resolve the conflicts and we can reopen

@mroeschke mroeschke closed this Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: mixed_int_string Index
3 participants