|
17 | 17 | ("uint16", [1, 3, 2], pl.UInt16, np.uint16),
|
18 | 18 | ("uint32", [1, 3, 2], pl.UInt32, np.uint32),
|
19 | 19 | ("uint64", [1, 3, 2], pl.UInt64, np.uint64),
|
| 20 | + ("float16", [-123.0, 0.0, 456.0], pl.Float32, np.float16), |
20 | 21 | ("float32", [21.7, 21.8, 21], pl.Float32, np.float32),
|
21 | 22 | ("float64", [21.7, 21.8, 21], pl.Float64, np.float64),
|
22 | 23 | ("bool", [True, False, False], pl.Boolean, np.bool_),
|
@@ -77,3 +78,25 @@ def test_numpy_disambiguation() -> None:
|
77 | 78 |
|
78 | 79 | def test_respect_dtype_with_series_from_numpy() -> None:
|
79 | 80 | assert pl.Series("foo", np.array([1, 2, 3]), dtype=pl.UInt32).dtype == pl.UInt32
|
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.parametrize( |
| 84 | + ("np_dtype_cls", "expected_pl_dtype"), |
| 85 | + [ |
| 86 | + (np.int8, pl.Int8), |
| 87 | + (np.int16, pl.Int16), |
| 88 | + (np.int32, pl.Int32), |
| 89 | + (np.int64, pl.Int64), |
| 90 | + (np.uint8, pl.UInt8), |
| 91 | + (np.uint16, pl.UInt16), |
| 92 | + (np.uint32, pl.UInt32), |
| 93 | + (np.uint64, pl.UInt64), |
| 94 | + (np.float16, pl.Float32), # << note: we don't currently have a native f16 |
| 95 | + (np.float32, pl.Float32), |
| 96 | + (np.float64, pl.Float64), |
| 97 | + ], |
| 98 | +) |
| 99 | +def test_init_from_numpy_values(np_dtype_cls: Any, expected_pl_dtype: Any) -> None: |
| 100 | + # test init from raw numpy values (vs arrays) |
| 101 | + s = pl.Series("n", [np_dtype_cls(0), np_dtype_cls(4), np_dtype_cls(8)]) |
| 102 | + assert s.dtype == expected_pl_dtype |
0 commit comments