-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
started to fixturize pandas/tests/base #31701
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
Changes from 3 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,76 @@ 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 """ | ||
data = np.random.randn(len(index)) | ||
return pd.Series(data, index=index, name=index.name) | ||
|
||
|
||
_series = { | ||
f"series-with-{id_}-index": _create_series(index) | ||
for id_, index in indices_dict.items() | ||
} | ||
|
||
|
||
def _create_narrow_series(dtype): | ||
""" Helper for the _narrow_series dict """ | ||
index = indices_dict["int"].copy() | ||
size = len(index) | ||
if np.issubdtype(dtype, np.floating): | ||
data = np.random.choice(size, size=size, replace=False) | ||
elif np.issubdtype(dtype, np.integer): | ||
data = np.random.randn(size) | ||
else: | ||
raise ValueError(f"Received an unexpected data_dtype: {dtype}") | ||
return pd.Series(data.astype(dtype), index=index, name="a") | ||
SaturnFromTitan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
_narrow_series = { | ||
"float32-series": _create_narrow_series(np.float32), | ||
"int8-series": _create_narrow_series(np.int8), | ||
"int16-series": _create_narrow_series(np.int16), | ||
"int32-series": _create_narrow_series(np.int32), | ||
"uint8-series": _create_narrow_series(np.uint8), | ||
"uint16-series": _create_narrow_series(np.uint16), | ||
"uint32-series": _create_narrow_series(np.uint32), | ||
} | ||
|
||
_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.