123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import operator
- import pytest
- from pandas import (
- Series,
- options,
- )
- @pytest.fixture
- def dtype():
- """A fixture providing the ExtensionDtype to validate."""
- raise NotImplementedError
- @pytest.fixture
- def data():
- """
- Length-100 array for this type.
- * data[0] and data[1] should both be non missing
- * data[0] and data[1] should not be equal
- """
- raise NotImplementedError
- @pytest.fixture
- def data_for_twos():
- """Length-100 array in which all the elements are two."""
- raise NotImplementedError
- @pytest.fixture
- def data_missing():
- """Length-2 array with [NA, Valid]"""
- raise NotImplementedError
- @pytest.fixture(params=["data", "data_missing"])
- def all_data(request, data, data_missing):
- """Parametrized fixture giving 'data' and 'data_missing'"""
- if request.param == "data":
- return data
- elif request.param == "data_missing":
- return data_missing
- @pytest.fixture
- def data_repeated(data):
- """
- Generate many datasets.
- Parameters
- ----------
- data : fixture implementing `data`
- Returns
- -------
- Callable[[int], Generator]:
- A callable that takes a `count` argument and
- returns a generator yielding `count` datasets.
- """
- def gen(count):
- for _ in range(count):
- yield data
- return gen
- @pytest.fixture
- def data_for_sorting():
- """
- Length-3 array with a known sort order.
- This should be three items [B, C, A] with
- A < B < C
- """
- raise NotImplementedError
- @pytest.fixture
- def data_missing_for_sorting():
- """
- Length-3 array with a known sort order.
- This should be three items [B, NA, A] with
- A < B and NA missing.
- """
- raise NotImplementedError
- @pytest.fixture
- def na_cmp():
- """
- Binary operator for comparing NA values.
- Should return a function of two arguments that returns
- True if both arguments are (scalar) NA for your type.
- By default, uses ``operator.is_``
- """
- return operator.is_
- @pytest.fixture
- def na_value():
- """The scalar missing value for this type. Default 'None'"""
- return None
- @pytest.fixture
- def data_for_grouping():
- """
- Data for factorization, grouping, and unique tests.
- Expected to be like [B, B, NA, NA, A, A, B, C]
- Where A < B < C and NA is missing
- """
- raise NotImplementedError
- @pytest.fixture(params=[True, False])
- def box_in_series(request):
- """Whether to box the data in a Series"""
- return request.param
- @pytest.fixture(
- params=[
- lambda x: 1,
- lambda x: [1] * len(x),
- lambda x: Series([1] * len(x)),
- lambda x: x,
- ],
- ids=["scalar", "list", "series", "object"],
- )
- def groupby_apply_op(request):
- """
- Functions to test groupby.apply().
- """
- return request.param
- @pytest.fixture(params=[True, False])
- def as_frame(request):
- """
- Boolean fixture to support Series and Series.to_frame() comparison testing.
- """
- return request.param
- @pytest.fixture(params=[True, False])
- def as_series(request):
- """
- Boolean fixture to support arr and Series(arr) comparison testing.
- """
- return request.param
- @pytest.fixture(params=[True, False])
- def use_numpy(request):
- """
- Boolean fixture to support comparison testing of ExtensionDtype array
- and numpy array.
- """
- return request.param
- @pytest.fixture(params=["ffill", "bfill"])
- def fillna_method(request):
- """
- Parametrized fixture giving method parameters 'ffill' and 'bfill' for
- Series.fillna(method=<method>) testing.
- """
- return request.param
- @pytest.fixture(params=[True, False])
- def as_array(request):
- """
- Boolean fixture to support ExtensionDtype _from_sequence method testing.
- """
- return request.param
- @pytest.fixture
- def invalid_scalar(data):
- """
- A scalar that *cannot* be held by this ExtensionArray.
- The default should work for most subclasses, but is not guaranteed.
- If the array can hold any item (i.e. object dtype), then use pytest.skip.
- """
- return object.__new__(object)
- @pytest.fixture
- def using_copy_on_write() -> bool:
- """
- Fixture to check if Copy-on-Write is enabled.
- """
- return options.mode.copy_on_write and options.mode.data_manager == "block"
|