-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Conversation
pandas/tests/indexes/test_base.py
Outdated
# 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): |
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.
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
pandas/tests/indexes/test_base.py
Outdated
def test_map_tseries_indices_return_index(self): | ||
date_index = tm.makeDateIndex(10) | ||
@pytest.mark.parametrize("attr", [ | ||
'makeDateIndex', 'makePeriodIndex', 'makeTimedeltaIndex']) |
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.
Will most likely replace with a fixture in the future, but made sense to parametrize for now
pandas/tests/indexes/test_base.py
Outdated
def test_difference(self): | ||
|
||
@pytest.mark.parametrize("second_nm,exp", [ | ||
(None, None), ('name', 'name')]) |
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.
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
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.
ok by me
pandas/tests/indexes/test_base.py
Outdated
@pytest.mark.parametrize("attr,exp", [ | ||
('strIndex', False), ('boolIndex', False), ('catIndex', False), | ||
('intIndex', True), ('dateIndex', False), ('floatIndex', True)]) | ||
def test_is_numeric(self, attr, exp): |
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 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
pandas/tests/indexes/test_base.py
Outdated
@@ -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): |
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.
Was only testing np.nan
and None
before but figured this was a good use case for the new nulls fixture
pandas/tests/indexes/test_base.py
Outdated
formatted = index.format() | ||
expected = [str(index[0]), str(index[1]), u('NaN')] | ||
assert formatted == expected | ||
def test_format_missing_obj(self, nulls_fixture): |
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.
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
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.
sure
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.
looks good. if can fix the naming then looks good to merge
pandas/tests/indexes/test_base.py
Outdated
|
||
# preserve names | ||
@pytest.mark.parametrize("first_nm,sec_nm,exp_nm", [ |
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.
ideally can you spell things out a bit more, e.g. first_name, second_name, expected_name
are just fine
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.
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)
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.
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)
pandas/tests/indexes/test_base.py
Outdated
second.name = 'B' | ||
intersect = first.intersection(second) | ||
assert intersect.name is None | ||
@pytest.mark.parametrize("idx2,keeps_nm", [ |
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.
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", [ |
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 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)
pandas/tests/indexes/test_base.py
Outdated
|
||
first = Index([], name='A') | ||
second = Index(list('ab')) | ||
@pytest.mark.parametrize("first,second,nm", [ |
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.
maybe could replace this with 2 parameterize (for a cartesian product of the inputs)
pandas/tests/indexes/test_base.py
Outdated
@@ -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", [ |
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.
name, expected
pandas/tests/indexes/test_base.py
Outdated
def test_difference(self): | ||
|
||
@pytest.mark.parametrize("second_nm,exp", [ | ||
(None, None), ('name', 'name')]) |
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.
ok by me
pandas/tests/indexes/test_base.py
Outdated
formatted = index.format() | ||
expected = [str(index[0]), str(index[1]), u('NaN')] | ||
assert formatted == expected | ||
def test_format_missing_obj(self, nulls_fixture): |
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.
sure
pandas/tests/indexes/test_base.py
Outdated
(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): |
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.
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
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.
Yep - I have this as the last TODO in the referenced issue so we don't lose sight of it
Codecov Report
@@ Coverage Diff @@
## master #20813 +/- ##
=======================================
Coverage 91.77% 91.77%
=======================================
Files 153 153
Lines 49265 49265
=======================================
Hits 45215 45215
Misses 4050 4050
Continue to review full report at Codecov.
|
thanks @WillAyd |
progress towards #20812