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

REF/TST: Add more pytest idiom to indexing/multiindex/test_getitem.py #24053

Merged
merged 8 commits into from
Dec 11, 2018

Conversation

simonjayhawkins
Copy link
Member

@simonjayhawkins simonjayhawkins commented Dec 2, 2018

xref #24040

for this pass:

  • the Test classes have been removed.

  • catch_warnings used for the .ix deprecation replaced with @pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") at test level.

cc @jreback @gfyoung

@pep8speaks
Copy link

pep8speaks commented Dec 2, 2018

Hello @simonjayhawkins! Thanks for updating the PR.

Comment last updated on December 10, 2018 at 16:06 Hours UTC

@gfyoung gfyoung added Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Dec 2, 2018
result = s.xs('one', level='L2')
expected = Series([1, 3], index=['a', 'b'])
expected.index.set_names(['L1'], inplace=True)
tm.assert_series_equal(result, expected)
Copy link
Member

Choose a reason for hiding this comment

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

Can we break this massive test up into smaller ones?

tm.assert_series_equal(result, expected)


def test_getitem_duplicates_multiindex():
Copy link
Contributor

Choose a reason for hiding this comment

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

can you try to parameteize this on the input frame / expected output.

Copy link
Contributor

Choose a reason for hiding this comment

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

might make sense to split out the empty case to a new test

df['foo']['one'] = 2
return df

pytest.raises(com.SettingWithCopyError, f)
Copy link
Member

Choose a reason for hiding this comment

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

Any error message worth checking?

@codecov
Copy link

codecov bot commented Dec 2, 2018

Codecov Report

Merging #24053 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24053   +/-   ##
=======================================
  Coverage   42.45%   42.45%           
=======================================
  Files         161      161           
  Lines       51561    51561           
=======================================
  Hits        21888    21888           
  Misses      29673    29673
Flag Coverage Δ
#single 42.45% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/strings.py 33% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92d25f0...47c4ce8. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 2, 2018

Codecov Report

Merging #24053 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24053   +/-   ##
=======================================
  Coverage   92.21%   92.21%           
=======================================
  Files         162      162           
  Lines       51761    51761           
=======================================
  Hits        47731    47731           
  Misses       4030     4030
Flag Coverage Δ
#multiple 90.61% <ø> (ø) ⬆️
#single 43% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5389987...3ff6159. Read the comment docs.

tm.assert_series_equal(result, expected)

# xs
result = s.xs(0, level=0)
Copy link
Member Author

Choose a reason for hiding this comment

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

@jreback should this be result = s.xs(0, level=1)?

Copy link
Member Author

Choose a reason for hiding this comment

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

we could then paramatrize..

@pytest.mark.parametrize('access_method', [lambda s, x: s[:, x],
                                           lambda s, x: s.loc[:, x],
                                           lambda s, x: s.xs(x, level=1)])
@pytest.mark.parametrize('level1_value, expected', [
    (0, Series([1], index=[0])),
    (1, Series([2, 3], index=[1, 2]))
])
def test_series_getitem_multiindex(access_method, level1_value, expected):

    # GH 6018
    # series regression getitem with a multi-index

    s = Series([1, 2, 3])
    s.index = MultiIndex.from_tuples([(0, 0), (1, 1), (2, 1)])
    result = access_method(s, level1_value)
    tm.assert_series_equal(result, expected)

or is this OTT.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, you certainly parameterize this

@simonjayhawkins
Copy link
Member Author

@jreback @gfyoung

test_series_getitem_multiindex and test_getitem_duplicates_multiindex split and parametrized. error messages checked.

carry on and split and parametrize the remaining tests in this file within this PR or limit the diff?

@jreback jreback added this to the 0.24.0 milestone Dec 11, 2018
@jreback jreback merged commit 9f29f88 into pandas-dev:master Dec 11, 2018
@jreback
Copy link
Contributor

jreback commented Dec 11, 2018

thanks @simonjayhawkins keep em coming! I don't mind bigger ones, main issue is there are some other parts moving so easiest to get them in in self-contained units.

thoo added a commit to thoo/pandas that referenced this pull request Dec 12, 2018
* upstream/master:
  pct change bug issue 21200 (pandas-dev#21235)
  DOC: Fix summaries not ending with a period (pandas-dev#24190)
  DOC: Add back currentmodule to api.rst (pandas-dev#24232)
  DOC: Fixed implicit imports for whatsnew (v >= version 20.0) (pandas-dev#24199)
  remove enum import for PY2 compat, xref pandas-dev#22802 (pandas-dev#24170)
  CI: Simplify Azure Pipelines configuration files (pandas-dev#23111)
  REF/TST: Add more pytest idiom to indexing/multiindex/test_getitem.py (pandas-dev#24053)
@simonjayhawkins simonjayhawkins deleted the mi-getitem branch December 13, 2018 12:57
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 MultiIndex Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants