|
8 | 8 | from pandera import Column, DataFrameSchema, Index, MultiIndex, \
|
9 | 9 | SeriesSchema, Bool, Category, Check, DateTime, Float, Int, Object, \
|
10 | 10 | String, Timedelta, check_input, check_output, Hypothesis
|
| 11 | +from pandera import dtypes |
11 | 12 | from scipy import stats
|
12 | 13 |
|
13 | 14 |
|
@@ -384,12 +385,42 @@ def _assert_expectation(result_df):
|
384 | 385 | transformer.transform_secord_arg_with_dict_getter(None, dataframe))
|
385 | 386 |
|
386 | 387 |
|
387 |
| -def test_string_dtypes(): |
388 |
| - # TODO: add tests for all datatypes |
389 |
| - schema = DataFrameSchema( |
390 |
| - {"col": Column("float64", nullable=True)}) |
391 |
| - df = pd.DataFrame({"col": [np.nan, 1.0, 2.0]}) |
392 |
| - assert isinstance(schema.validate(df), pd.DataFrame) |
| 388 | +def test_dtypes(): |
| 389 | + for dtype in [ |
| 390 | + dtypes.Float, |
| 391 | + dtypes.Float16, |
| 392 | + dtypes.Float32, |
| 393 | + dtypes.Float64]: |
| 394 | + schema = DataFrameSchema({"col": Column(dtype, nullable=False)}) |
| 395 | + validated_df = schema.validate( |
| 396 | + pd.DataFrame( |
| 397 | + {"col": [-123.1, -7654.321, 1.0, 1.1, 1199.51, 5.1, 4.6]}, |
| 398 | + dtype=dtype.value)) |
| 399 | + assert isinstance(validated_df, pd.DataFrame) |
| 400 | + |
| 401 | + for dtype in [ |
| 402 | + dtypes.Int, |
| 403 | + dtypes.Int8, |
| 404 | + dtypes.Int16, |
| 405 | + dtypes.Int32, |
| 406 | + dtypes.Int64]: |
| 407 | + schema = DataFrameSchema({"col": Column(dtype, nullable=False)}) |
| 408 | + validated_df = schema.validate( |
| 409 | + pd.DataFrame( |
| 410 | + {"col": [-712, -4, -321, 0, 1, 777, 5, 123, 9000]}, |
| 411 | + dtype=dtype.value)) |
| 412 | + assert isinstance(validated_df, pd.DataFrame) |
| 413 | + |
| 414 | + for dtype in [ |
| 415 | + dtypes.UInt8, |
| 416 | + dtypes.UInt16, |
| 417 | + dtypes.UInt32, |
| 418 | + dtypes.UInt64]: |
| 419 | + schema = DataFrameSchema({"col": Column(dtype, nullable=False)}) |
| 420 | + validated_df = schema.validate( |
| 421 | + pd.DataFrame( |
| 422 | + {"col": [1, 777, 5, 123, 9000]}, dtype=dtype.value)) |
| 423 | + assert isinstance(validated_df, pd.DataFrame) |
393 | 424 |
|
394 | 425 |
|
395 | 426 | def test_nullable_int():
|
|
0 commit comments