Skip to content

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

Merged
merged 9 commits into from
Nov 20, 2019

Conversation

ganevgv
Copy link
Contributor

@ganevgv ganevgv commented Nov 6, 2019

@alimcmaster1 alimcmaster1 added Testing pandas testing functions or related to the test suite Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 6, 2019
@gfyoung gfyoung added this to the 1.0 milestone Nov 7, 2019
@gfyoung gfyoung requested a review from toobaz November 7, 2019 04:28
Copy link
Member

@WillAyd WillAyd left a 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

# GH 20991
tuple_1 = tuple([1, 2])
tuple_2 = tuple([1])
df = DataFrame([[tuple_1], [tuple_2]], columns=["A"]).set_index("A")
Copy link
Member

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

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 @WillAyd - removed .set_index()

tuple_2 = tuple([1])
df = DataFrame([[tuple_1], [tuple_2]], columns=["A"]).set_index("A")

result = df.loc[[df.index[0]]]
Copy link
Member

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

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 @WillAyd - removed .index[...]

Copy link
Member

@WillAyd WillAyd left a 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?

@@ -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):
Copy link
Contributor

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)

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 for the feedback @jreback - now using parameterize

@ganevgv ganevgv requested a review from jreback November 10, 2019 15:19
@WillAyd
Copy link
Member

WillAyd commented Nov 20, 2019

@ganevgv can you resolve merge conflict and repush?

Copy link
Contributor

@jreback jreback left a 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

@@ -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])])
Copy link
Contributor

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

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, @jreback

@ganevgv ganevgv force-pushed the tests/df_single_tuples_indexing branch from 03e7178 to 2e38564 Compare November 20, 2019 15:24
@jreback jreback merged commit 9e7a733 into pandas-dev:master Nov 20, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using tuples as dataframe index, containing single entry makes rows impossible to select
5 participants