Skip to content

Commit

Permalink
Add tests for all functions in convert.py (#1715)
Browse files Browse the repository at this point in the history
* `from_dict` and `from_dicts` were not covered
* the other tests are the examples in docstrings
  • Loading branch information
zundertj committed Nov 9, 2021
1 parent 3058ba6 commit 184a296
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions py-polars/tests/test_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,39 @@ def test_from_pandas_categorical_none():
out = pl.from_pandas(s)
assert out.dtype == pl.Categorical
assert out.to_list() == ["a", "b", "c", None]


def test_from_dict():
data = {"a": [1, 2], "b": [3, 4]}
df = pl.from_dict(data)
assert df.shape == (2, 2)


def test_from_dicts():
data = [{"a": 1, "b": 4}, {"a": 2, "b": 5}, {"a": 3, "b": 6}]
df = pl.from_dicts(data)
assert df.shape == (3, 2)


def test_from_records():
data = [[1, 2, 3], [4, 5, 6]]
df = pl.from_records(data, columns=["a", "b"])
assert df.shape == (3, 2)


def test_from_arrow():
data = pa.table({"a": [1, 2, 3], "b": [4, 5, 6]})
df = pl.from_arrow(data)
assert df.shape == (3, 2)


def test_from_pandas_dataframe():
pd_df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=["a", "b", "c"])
df = pl.from_pandas(pd_df)
assert df.shape == (2, 3)


def test_from_pandas_series():
pd_series = pd.Series([1, 2, 3], name="pd")
df = pl.from_pandas(pd_series)
assert df.shape == (3,)

0 comments on commit 184a296

Please sign in to comment.