-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: add test for indexing with single/double tuples #29448
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: add test for indexing with single/double tuples #29448
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments to make the test more concise
pandas/tests/frame/test_indexing.py
Outdated
# GH 20991 | ||
tuple_1 = tuple([1, 2]) | ||
tuple_2 = tuple([1]) | ||
df = DataFrame([[tuple_1], [tuple_2]], columns=["A"]).set_index("A") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just construct idx = pd.Index(...)
before this and use index=idx
as part of the DataFrame constructors? Would be more concise than the current construction / set_index ops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @WillAyd - removed .set_index()
pandas/tests/frame/test_indexing.py
Outdated
tuple_2 = tuple([1]) | ||
df = DataFrame([[tuple_1], [tuple_2]], columns=["A"]).set_index("A") | ||
|
||
result = df.loc[[df.index[0]]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
df.loc[tuple_1]
; if you can avoid df.index[...]
calls here will make the test more concise, as accessing index values like that isn't related to the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @WillAyd - removed .index[...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great lgtm @toobaz care to take a look?
pandas/tests/frame/test_indexing.py
Outdated
@@ -2626,6 +2626,23 @@ def test_index_namedtuple(self): | |||
result = df.loc[IndexType("foo", "bar")]["A"] | |||
assert result == 1 | |||
|
|||
def test_index_single_double_tuples(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can parameterize this (e.g. pass in what you have as tuple_1, tuple_2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the feedback @jreback - now using parameterize
@ganevgv can you resolve merge conflict and repush? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase on master to get the new test file structure
pandas/tests/frame/test_indexing.py
Outdated
@@ -2626,6 +2626,17 @@ def test_index_namedtuple(self): | |||
result = df.loc[IndexType("foo", "bar")]["A"] | |||
assert result == 1 | |||
|
|||
@pytest.mark.parametrize("tpl", [tuple([1]), tuple([1, 2])]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file moved to pandas/tests/frame/indexing/test_indexing.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, @jreback
03e7178
to
2e38564
Compare
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff