def custom_eq_strategy( pandas_dtype: pa.DataType, strategy: st.SearchStrategy = None, *, value: Any, ): return st.just(value).map(strategies.to_numpy_dtype(pandas_dtype).type)
def test_field_element_strategy(data_type, data): """Test strategy for generating elements in columns/indexes.""" strategy = strategies.field_element_strategy(data_type) element = data.draw(strategy) expected_type = strategies.to_numpy_dtype(data_type).type assert element.dtype.type == expected_type with pytest.raises(pa.errors.BaseStrategyOnlyError): strategies.field_element_strategy( data_type, strategies.pandas_dtype_strategy(data_type))
def test_pandas_dtype_strategy(data_type, data): """Test that series can be constructed from pandas dtype.""" strategy = strategies.pandas_dtype_strategy(data_type) example = data.draw(strategy) expected_type = strategies.to_numpy_dtype(data_type).type assert example.dtype.type == expected_type chained_strategy = strategies.pandas_dtype_strategy(data_type, strategy) chained_example = data.draw(chained_strategy) assert chained_example.dtype.type == expected_type
def test_check_strategy_continuous(data_type, data): """Test built-in check strategies can generate continuous data.""" np_dtype = strategies.to_numpy_dtype(data_type) value = data.draw( npst.from_dtype( strategies.to_numpy_dtype(data_type), allow_nan=False, allow_infinity=False, )) # don't overstep bounds of representation hypothesis.assume(np.finfo(np_dtype).min < value < np.finfo(np_dtype).max) assert data.draw(strategies.ne_strategy(data_type, value=value)) != value assert data.draw(strategies.eq_strategy(data_type, value=value)) == value assert (data.draw(strategies.gt_strategy(data_type, min_value=value)) > value) assert (data.draw(strategies.ge_strategy(data_type, min_value=value)) >= value) assert (data.draw(strategies.lt_strategy(data_type, max_value=value)) < value) assert (data.draw(strategies.le_strategy(data_type, max_value=value)) <= value)
def test_pandas_dtype_strategy(data_type, data): """Test that series can be constructed from pandas dtype.""" strategy = strategies.pandas_dtype_strategy(data_type) example = data.draw(strategy) expected_type = strategies.to_numpy_dtype(data_type).type if isinstance(example, pd.Timestamp): example = example.to_numpy() assert example.dtype.type == expected_type chained_strategy = strategies.pandas_dtype_strategy(data_type, strategy) chained_example = data.draw(chained_strategy) if isinstance(chained_example, pd.Timestamp): chained_example = chained_example.to_numpy() assert chained_example.dtype.type == expected_type