Skip to content

Commit

Permalink
python: allow empty series creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 19, 2021
1 parent 173e11f commit 5692bbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion py-polars/polars/eager/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ def __init__(
raise ValueError(
f"Constructing a Series with a dict is not supported for {values}"
)
elif values is None and dtype is None:
dtype = Float32
values = []
elif values is None:
raise ValueError("Series values cannot be None.")
values = []

# castable to numpy
if not isinstance(values, np.ndarray) and not nullable:
Expand Down
13 changes: 9 additions & 4 deletions py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def test_init_inputs():

pl.Series([1, 2])
pl.Series(values=[1, 2])
pl.Series()
pl.Series("a")

# Bad inputs
with pytest.raises(ValueError):
pl.Series()
with pytest.raises(ValueError):
pl.Series("a")
with pytest.raises(ValueError):
pl.Series([1, 2, 3], [1, 2, 3])
with pytest.raises(ValueError):
Expand Down Expand Up @@ -318,6 +316,13 @@ def test_iter():
assert sum(s) == 6


def test_empty():
a = pl.Series(dtype=pl.Int8)
assert a.dtype == pl.Int8
a = pl.Series()
assert a.dtype == pl.Float32


def test_describe():
num_s = pl.Series([1, 2, 3])
float_s = pl.Series([1.3, 4.6, 8.9])
Expand Down

0 comments on commit 5692bbc

Please sign in to comment.