Skip to content

Commit

Permalink
Fix and add test numpy 2d array Series init (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj committed Nov 21, 2021
1 parent 66dc057 commit 0c11e73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py-polars/polars/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def numpy_to_pyseries(
else:
return constructor(name, values, strict)
else:
return PySeries.new_object(name, values)
return PySeries.new_object(name, values, strict)


def _get_first_non_none(values: Sequence[Optional[Any]]) -> Any:
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def test_init_inputs() -> None:
assert pl.Series(values=["foo", "bar"]).dtype == pl.Utf8
assert pl.Series("a", [pl.Series([1, 2, 4]), pl.Series([3, 2, 1])]).dtype == pl.List

# 2d numpy array
res = pl.Series(name="a", values=np.array([[1, 2], [3, 4]]))
assert all(res[0] == np.array([1, 2]))
assert all(res[1] == np.array([3, 4]))

# Bad inputs
with pytest.raises(ValueError):
pl.Series([1, 2, 3], [1, 2, 3])
Expand Down

0 comments on commit 0c11e73

Please sign in to comment.