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: Refactor pandas/tests/base - part3 #30147

Merged
merged 27 commits into from
Feb 1, 2020

Conversation

SaturnFromTitan
Copy link
Contributor

@SaturnFromTitan SaturnFromTitan commented Dec 8, 2019

Part of #23877

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

Starting to dissolve the Ops Mixin to drive fixturization of pandas/tests/base/

@SaturnFromTitan SaturnFromTitan changed the title added new fixtures that can replace the Ops mixin CLN: Refactor pandas/tests/base - part3 Dec 8, 2019
@SaturnFromTitan SaturnFromTitan force-pushed the refactor-test-base-part3 branch from 0d9a817 to 1685be9 Compare December 8, 2019 21:57
@SaturnFromTitan SaturnFromTitan force-pushed the refactor-test-base-part3 branch from 1685be9 to 4d1750c Compare December 8, 2019 22:03
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
@WillAyd WillAyd added the Testing pandas testing functions or related to the test suite label Dec 9, 2019
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/tests/base/test_ops.py Outdated Show resolved Hide resolved
@jschendel jschendel added the Clean label Dec 9, 2019
@jschendel jschendel added this to the 1.0 milestone Dec 9, 2019
@SaturnFromTitan
Copy link
Contributor Author

Thanks for your reviews!

@SaturnFromTitan
Copy link
Contributor Author

SaturnFromTitan commented Dec 9, 2019

I addressed all your comments @WillAyd @jschendel. Please have another look

pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/conftest.py Outdated Show resolved Hide resolved
pandas/tests/base/utils.py Outdated Show resolved Hide resolved
@SaturnFromTitan
Copy link
Contributor Author

@jreback Like mentioned in the issue description and in this comment: The utils and fixtures in this PR will be used in more places than just tests/base. That's why I put the fixtures directly into the base conftest. Applying them right away would have yielded a huge PR, so I wanted to split it into parts.

I see now that not using the utils and fixtures anywhere makes it impossible to understand their purpose. I will update the PR and remove the usage of Ops in tests/indexes which needs much fewer changes than tests/base.

@jreback
Copy link
Contributor

jreback commented Dec 10, 2019

@jreback Like mentioned in the issue description and in this comment: The utils and fixtures in this PR will be used in more places than just tests/base. That's why I put the fixtures directly into the base conftest. Applying them right away would have yielded a huge PR, so I wanted to split it into parts.

I see now that not using the utils and fixtures anywhere makes it impossible to understand their purpose. I will update the PR and remove the usage of Ops in tests/indexes which needs much fewer changes than tests/base.

this is likely true, however, I would rather move them locally pandas/tests/base, THEN in a follow on conform names & patterns between multiple places in the codebase.

@SaturnFromTitan
Copy link
Contributor Author

Makes sense. It makes the PRs more atomic

@SaturnFromTitan
Copy link
Contributor Author

@jreback @WillAyd @jschendel
Thanks for your feedback. I added the following changes to the PR:

  1. I extended the scope of this PR and replaced the usage of the Ops mixin in tests/indexes/ to provide some more context of the added fixtures and utils.
  2. Like suggested, I moved the new fixtures into tests/indexes/conftest.py as that's the only place the fixtures are used for now
  3. I'm using the existing indeces_dict from tests/indexes/conftest.py now instead of creating my own indexes fixtures now.

Please have another look at the PR

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.

Looks good one comment

pandas/tests/indexes/datetimes/test_ops.py Outdated Show resolved Hide resolved
@SaturnFromTitan SaturnFromTitan force-pushed the refactor-test-base-part3 branch from 340b47f to 69a0a0d Compare January 23, 2020 23:13
f = lambda x: isinstance(x, DatetimeIndex)
self.check_ops_properties(DatetimeIndex._field_ops, f)
self.check_ops_properties(DatetimeIndex._object_ops, f)
self.check_ops_properties(DatetimeIndex._bool_ops, f)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already tested in pandas/tests/series/test_datetime_values.py::test_dt_namespace_accessor

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. test_dt_namespace_accessor could use a good refactor if youre up to it (separate PR)

@@ -83,74 +75,29 @@ def setup_method(self, method):

self.objs = self.indexes + self.series + self.narrow_series

def check_ops_properties(self, props, filter=None, ignore_failures=False):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method was only used in pandas/tests/indexes. I could remove all tests where it was used though as they were redundant (already tested in pandas/tests/series/test_datetime_values.py::test_dt_namespace_accessor)

self.is_valid_objs = [o for o in self.objs if mask(o)]
self.not_valid_objs = [o for o in self.objs if not mask(o)]

def test_ops_properties(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already tested in pandas/tests/series/test_datetime_values.py::test_dt_namespace_accessor

self.is_valid_objs = [o for o in self.objs if mask(o)]
self.not_valid_objs = []

def test_ops_properties(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already tested in pandas/tests/series/test_datetime_values.py::test_dt_namespace_accessor

@SaturnFromTitan
Copy link
Contributor Author

@jreback Thanks to your comment about redundant tests I could reduce the scope of this PR quite a bit further. It's ready to review now.

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.

ok looks pretty good. @jbrockmendel if you'd have a look

pandas/tests/base/test_ops.py Show resolved Hide resolved
pandas/tests/indexes/common.py Outdated Show resolved Hide resolved
@@ -265,7 +265,7 @@ def _get_opstr(op):
rtruediv: "/",
operator.floordiv: "//",
rfloordiv: "//",
operator.mod: None, # TODO: Why None for mod but '%' for rmod?
operator.mod: "%",
Copy link
Member

Choose a reason for hiding this comment

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

do we have tests where this makes a difference? maybe this lets us use numexpr and performance is affected?

Copy link
Contributor Author

@SaturnFromTitan SaturnFromTitan Jan 26, 2020

Choose a reason for hiding this comment

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

Yeah, I wasn't sure about this one. Thought I give it a try and see if any of the CI hooks is failing. The 2 failing ones in pandas-dev.pandas (Linux py37_locale) look unrelated though. I'll rebase and try again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbrockmendel CI is green now, so all tests seem to be fine with this change.
@jreback do you have any concerns about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

looks ok, original issue is that this looks like a format string to python

@SaturnFromTitan
Copy link
Contributor Author

Friendly reminder @jreback

@jreback jreback added this to the 1.1 milestone Feb 1, 2020
@@ -265,7 +265,7 @@ def _get_opstr(op):
rtruediv: "/",
operator.floordiv: "//",
rfloordiv: "//",
operator.mod: None, # TODO: Why None for mod but '%' for rmod?
operator.mod: "%",
Copy link
Contributor

Choose a reason for hiding this comment

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

looks ok, original issue is that this looks like a format string to python

@jreback jreback merged commit 01623f8 into pandas-dev:master Feb 1, 2020
@jreback
Copy link
Contributor

jreback commented Feb 1, 2020

thanks @SaturnFromTitan yeah love these test refactor PRs; we have built up some monotliths...though many are being taken down / split now, so thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants