-
-
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
started to fixturize pandas/tests/base #31701
started to fixturize pandas/tests/base #31701
Conversation
pandas/tests/base/conftest.py
Outdated
@@ -0,0 +1,52 @@ | |||
import numpy as np |
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.
Here's a link to the original mixin this aims to replace:
https://github.com/pandas-dev/pandas/blob/master/pandas/tests/base/test_ops.py#L43-L83
pandas/tests/base/conftest.py
Outdated
|
||
|
||
@pytest.fixture(params=_all_objs.keys()) | ||
def index_or_series_obj(request): |
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.
Hmm I think this is a rather complicated way of composing things. Given there is already a fixture for indeces
that does something very similar can we just not modify this to use that and create the Series objects as required?
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'm not sure I understand you right. What do you mean by "create the Series objects as required"?
I need a fixture to replace self.all_objs from the Ops
mixin. This will be used in a lot more places in pandas/tests/base/test_ops.py
, so I can't just construct the Series' in the test cases.
I was hoping that there are other fixtures which I could use instead of _series
and _narrow_series
, but I think I still know too little about the codebase to find them. I'd be grateful for any hints to point me in the right direction ✌️
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.
To rephrase I'm asking if there is a way to leverage the already existing indices fixture, as this duplicates part of the logic of that
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.
Not really. I checked two possibilities:
- Creating more parametrized fixtures for
series
andnarrow_series
:
@pytest.fixture
def series(indices):
data = np.random.randn(len(indices))
return pd.Series(data, index=indices, name=indices.name)
The problem is, that when using these fixtures in a test like
def test1(indices, series):
...
the product of all fixture values is executed instead of the union. So a lot of redundant test cases are run.
- Letting
index_or_series_obj
depend onindices
:
The problem is thatindex_or_series_obj
is supposed to have a different length. So this doesn't really work either.
-> Based on this, the current implementation seems to be the best we can do.
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.
Issue 1 and a potential solution (requires a new dependency) is well explained in this SO post.
pandas/tests/base/conftest.py
Outdated
} | ||
|
||
|
||
def _create_narrow_series(data_dtype): |
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.
just call this dtype, use the is_integer and so one for comparisons; we really try to avoid using numpy things generally (as they don't scale to all of our dtypes).
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.
@jreback I just tried that, but is_integer(np.int16)
is actually False
. Similar for the other dtypes or is_float
😐
pandas/tests/base/conftest.py
Outdated
import pytest | ||
|
||
import pandas as pd | ||
from pandas.tests.indexes.conftest import indices_dict |
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 would rather just move the indices_dict to pandas/conftest.py and create these helper series there (as fixtures). ok to do this in 2 PRs
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 just did it in this one. Please let me know if it's what you intended.
create these helper series there (as fixtures)
Not sure what you mean with "as fixtures". Like described in my comment above, I don't see a better way to create this index_or_series_obj
fixture
…_obj fixture there as well
c3cc757
to
0f88d47
Compare
I think I addressed all the review comments. Friendly ping @jreback @WillAyd @jbrockmendel |
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.
lgtm. some comments for followups; if you can do them (and track), then no-need to keep a public list, if you are busy pls make an issue with these types of TODOs
|
||
@pytest.fixture(params=indices_dict.keys()) | ||
def indices(request): | ||
# copy to avoid mutation, e.g. setting .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.
next time around can you give these doc-strings
@@ -953,3 +954,69 @@ def __len__(self): | |||
return self._data.__len__() | |||
|
|||
return TestNonDictMapping | |||
|
|||
|
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.
can you do 'sections' here e.g. some text markers so reading the file is easy (@jbrockmendel has added these in several files); this can be a followup PR.
@@ -34,6 +34,7 @@ | |||
period_range, | |||
) | |||
import pandas._testing as tm | |||
from pandas.conftest import indices_dict |
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.
we really want to avoid this import (but understand doing this in steps)
@@ -13,7 +13,7 @@ | |||
from pandas import Float64Index, Int64Index, RangeIndex, UInt64Index | |||
import pandas._testing as tm | |||
from pandas.api.types import pandas_dtype | |||
from pandas.tests.indexes.conftest import indices_dict | |||
from pandas.conftest import indices_dict |
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.
same
xref: #31989 |
Part of #23877
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
I didn't apply the fixtures to the rest of
test_ops.py
yet since @jreback voiced some concerns in this comment.