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

CLN: Continued indexes/test_base.py cleanup #20813

Merged
merged 9 commits into from
Apr 27, 2018

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Apr 24, 2018

progress towards #20812

# preserve names
@pytest.mark.parametrize("first_nm,sec_nm,exp_nm", [
('A', 'A', 'A'), ('A', 'B', None), (None, 'B', None)])
def test_intersection_name_preservation2(self, first_nm, sec_nm, exp_nm):
Copy link
Member Author

Choose a reason for hiding this comment

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

Kept as a separate test for now, but ideally should be combined with the test above as they cover the same topics. Waiting until I get around to replacing the index class attrs with fixtures to explore in more detail

def test_map_tseries_indices_return_index(self):
date_index = tm.makeDateIndex(10)
@pytest.mark.parametrize("attr", [
'makeDateIndex', 'makePeriodIndex', 'makeTimedeltaIndex'])
Copy link
Member Author

Choose a reason for hiding this comment

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

Will most likely replace with a fixture in the future, but made sense to parametrize for now

def test_difference(self):

@pytest.mark.parametrize("second_nm,exp", [
(None, None), ('name', 'name')])
Copy link
Member Author

Choose a reason for hiding this comment

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

Might be over-engineering the parameters in this case, but figure if we wanted to expand to cover more scenarios this is a better framework to do so

Copy link
Contributor

Choose a reason for hiding this comment

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

ok by me

@pytest.mark.parametrize("attr,exp", [
('strIndex', False), ('boolIndex', False), ('catIndex', False),
('intIndex', True), ('dateIndex', False), ('floatIndex', True)])
def test_is_numeric(self, attr, exp):
Copy link
Member Author

Choose a reason for hiding this comment

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

This and the two tests below it did not consistently test all of the index types so I've added where missing for better coverage. Should ultimately be replaced with fixtures but same concept will apply

@@ -1142,19 +1106,21 @@ def test_format(self):
expected = [str(index[0])]
assert formatted == expected

self.strIndex[:0].format()

def test_format_missing(self, nulls_fixture):
Copy link
Member Author

Choose a reason for hiding this comment

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

Was only testing np.nan and None before but figured this was a good use case for the new nulls fixture

formatted = index.format()
expected = [str(index[0]), str(index[1]), u('NaN')]
assert formatted == expected
def test_format_missing_obj(self, nulls_fixture):
Copy link
Member Author

Choose a reason for hiding this comment

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

Trying to balance too many changes but am leaning towards combining this with the above test. Both are pretty similar but leave strange gaps in what they test across the float and object types

Copy link
Contributor

Choose a reason for hiding this comment

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

sure

@jreback jreback added Testing pandas testing functions or related to the test suite Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 24, 2018
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.

looks good. if can fix the naming then looks good to merge


# preserve names
@pytest.mark.parametrize("first_nm,sec_nm,exp_nm", [
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally can you spell things out a bit more, e.g. first_name, second_name, expected_name are just fine

Copy link
Member Author

Choose a reason for hiding this comment

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

Would you prefer generally using result and expected over res and exp? I've seen both and typically use the latter but if we have a preference we could start being explicit about those standards (maybe in TESTING_README)

Copy link
Contributor

Choose a reason for hiding this comment

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

I really prefer result, expected

the code base mostly has these, but yes res, exp are also used. we should standardize and maybe check this in lint. (you can create an issue if you'd like)

second.name = 'B'
intersect = first.intersection(second)
assert intersect.name is None
@pytest.mark.parametrize("idx2,keeps_nm", [
Copy link
Contributor

Choose a reason for hiding this comment

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

so keeps_nm -> keeps_name and normalize the input params, e.g. index (or index2 or other) as appropriate

union = first.union(second)
assert tm.equalContents(union, everything)

@pytest.mark.parametrize("klass", [
Copy link
Contributor

Choose a reason for hiding this comment

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

this notion of klass we have all over the place, sometimes its also called box (not necessary to do here, just letting you know, prob best to update the issue you created)


first = Index([], name='A')
second = Index(list('ab'))
@pytest.mark.parametrize("first,second,nm", [
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe could replace this with 2 parameterize (for a cartesian product of the inputs)

@@ -967,18 +933,14 @@ def test_append_multiple(self):
result = index.append([])
tm.assert_index_equal(result, index)

def test_append_empty_preserve_name(self):
@pytest.mark.parametrize("nm,exp", [
Copy link
Contributor

Choose a reason for hiding this comment

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

name, expected

def test_difference(self):

@pytest.mark.parametrize("second_nm,exp", [
(None, None), ('name', 'name')])
Copy link
Contributor

Choose a reason for hiding this comment

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

ok by me

formatted = index.format()
expected = [str(index[0]), str(index[1]), u('NaN')]
assert formatted == expected
def test_format_missing_obj(self, nulls_fixture):
Copy link
Contributor

Choose a reason for hiding this comment

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

sure

(Index([3, 4, 5, 6, 7], name="idx"), True), # preserve same name
(Index([3, 4, 5, 6, 7], name="other"), False), # drop diff names
(Index([3, 4, 5, 6, 7]), False)])
def test_intersection_name_preservation(self, idx2, keeps_nm):
Copy link
Contributor

Choose a reason for hiding this comment

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

side note, we prob need to split out test_base into multiple files its growing pretty big (do this as a separate step), these might be things like: test_indexing.py, test_missing.py, test_set_ops.py etc, in essence mirroring the various sub-files we do for series ops

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep - I have this as the last TODO in the referenced issue so we don't lose sight of it

@codecov
Copy link

codecov bot commented Apr 25, 2018

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #20813   +/-   ##
=======================================
  Coverage   91.77%   91.77%           
=======================================
  Files         153      153           
  Lines       49265    49265           
=======================================
  Hits        45215    45215           
  Misses       4050     4050
Flag Coverage Δ
#multiple 90.16% <ø> (ø) ⬆️
#single 41.86% <ø> (ø) ⬆️

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 8bee97a...1acfda1. Read the comment docs.

@jreback jreback added this to the 0.23.0 milestone Apr 27, 2018
@jreback jreback merged commit 96f2f57 into pandas-dev:master Apr 27, 2018
@jreback
Copy link
Contributor

jreback commented Apr 27, 2018

thanks @WillAyd

@WillAyd WillAyd deleted the idx-clnup2 branch May 14, 2018 21:11
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.

2 participants