-
-
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
Changes from all commits
3a9802d
ac4a5eb
0f88d47
e865e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from pandas import DataFrame | ||
import pandas._testing as tm | ||
from pandas.core import ops | ||
from pandas.core.indexes.api import Index, MultiIndex | ||
|
||
hypothesis.settings.register_profile( | ||
"ci", | ||
|
@@ -953,3 +954,69 @@ def __len__(self): | |
return self._data.__len__() | ||
|
||
return TestNonDictMapping | ||
|
||
|
||
indices_dict = { | ||
"unicode": tm.makeUnicodeIndex(100), | ||
"string": tm.makeStringIndex(100), | ||
"datetime": tm.makeDateIndex(100), | ||
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"), | ||
"period": tm.makePeriodIndex(100), | ||
"timedelta": tm.makeTimedeltaIndex(100), | ||
"int": tm.makeIntIndex(100), | ||
"uint": tm.makeUIntIndex(100), | ||
"range": tm.makeRangeIndex(100), | ||
"float": tm.makeFloatIndex(100), | ||
"bool": tm.makeBoolIndex(2), | ||
"categorical": tm.makeCategoricalIndex(100), | ||
"interval": tm.makeIntervalIndex(100), | ||
"empty": Index([]), | ||
"tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])), | ||
"repeats": Index([0, 0, 1, 1, 2, 2]), | ||
} | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.fixture(params=indices_dict.keys()) | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def indices(request): | ||
# copy to avoid mutation, e.g. setting .name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. next time around can you give these doc-strings |
||
return indices_dict[request.param].copy() | ||
|
||
|
||
def _create_series(index): | ||
""" Helper for the _series dict """ | ||
size = len(index) | ||
data = np.random.randn(size) | ||
return pd.Series(data, index=index, name="a") | ||
|
||
|
||
_series = { | ||
f"series-with-{index_id}-index": _create_series(index) | ||
for index_id, index in indices_dict.items() | ||
} | ||
|
||
|
||
_narrow_dtypes = [ | ||
np.float16, | ||
np.float32, | ||
np.int8, | ||
np.int16, | ||
np.int32, | ||
np.uint8, | ||
np.uint16, | ||
np.uint32, | ||
] | ||
_narrow_series = { | ||
f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype) | ||
for dtype in _narrow_dtypes | ||
} | ||
|
||
_index_or_series_objs = {**indices_dict, **_series, **_narrow_series} | ||
|
||
|
||
@pytest.fixture(params=_index_or_series_objs.keys()) | ||
SaturnFromTitan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def index_or_series_obj(request): | ||
""" | ||
Fixture for tests on indexes, series and series with a narrow dtype | ||
copy to avoid mutation, e.g. setting .name | ||
""" | ||
return _index_or_series_objs[request.param].copy(deep=True) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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) |
||
from pandas.core.indexes.api import ( | ||
Index, | ||
MultiIndex, | ||
|
@@ -42,7 +43,6 @@ | |
ensure_index_from_sequences, | ||
) | ||
from pandas.tests.indexes.common import Base | ||
from pandas.tests.indexes.conftest import indices_dict | ||
|
||
|
||
class TestIndex(Base): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
COMPATIBLE_INCONSISTENT_PAIRS = { | ||
(Int64Index, RangeIndex): (tm.makeIntIndex, tm.makeRangeIndex), | ||
|
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.