Skip to content

Commit

Permalink
python: boolean numpy array to boolean type
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 12, 2021
1 parent 0847ecd commit b87be32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion py-polars/polars/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def polars_type_to_constructor(
np.uint32: PySeries.new_u32,
np.uint64: PySeries.new_u64,
np.str_: PySeries.new_str,
bool: PySeries.new_bool,
np.bool_: PySeries.new_bool,
}


Expand Down
12 changes: 8 additions & 4 deletions py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ def test_init_inputs():
pl.Series(name="a", values=[1, 2])
pl.Series(values=[1, 2], name="a")

pl.Series([1, 2])
pl.Series(values=[1, 2])
pl.Series()
pl.Series("a")
assert pl.Series([1, 2]).dtype == pl.Int64
assert pl.Series(values=[1, 2]).dtype == pl.Int64
assert pl.Series("a").dtype == pl.Float32 # f32 type used in case of no data
assert pl.Series().dtype == pl.Float32
assert pl.Series(values=[True, False]).dtype == pl.Boolean
assert pl.Series(values=np.array([True, False])).dtype == pl.Boolean
assert pl.Series(values=np.array(["foo", "bar"])).dtype == pl.Utf8
assert pl.Series(values=["foo", "bar"]).dtype == pl.Utf8

# Bad inputs
with pytest.raises(ValueError):
Expand Down

0 comments on commit b87be32

Please sign in to comment.