Skip to content

Commit

Permalink
Add support for building dataframe from rows when they contain None f…
Browse files Browse the repository at this point in the history
…or Float32/Float64 values. (#2289)
  • Loading branch information
ghuls committed Jan 6, 2022
1 parent 9a22bb2 commit 98ccee4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions polars/polars-core/src/frame/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ impl Buffer {
(Datetime(builder, _, _), AnyValue::Datetime(v, _, _)) => builder.append_value(v),
#[cfg(feature = "dtype-time")]
(Time(builder), AnyValue::Time(v)) => builder.append_value(v),
(Float32(builder), AnyValue::Float32(v)) => builder.append_value(v),
(Float32(builder), AnyValue::Null) => builder.append_null(),
(Float64(builder), AnyValue::Float64(v)) => builder.append_value(v),
(Float64(builder), AnyValue::Null) => builder.append_null(),
(Utf8(builder), AnyValue::Utf8(v)) => builder.append_value(v),
(Utf8(builder), AnyValue::Null) => builder.append_null(),
(buf, val) => return Err(PolarsError::ValueError(format!("Could not append {:?} to builder {:?}; make sure that all rows have the same schema.", val, std::mem::discriminant(buf)).into()))
Expand Down
6 changes: 4 additions & 2 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ def test_init_ndarray() -> None:
truth = pl.DataFrame({"column_0": [1, 2], "column_1": [3, 4]})
assert df.frame_equal(truth)

df = pl.DataFrame(np.array([[1, 2], [3, 4]]), orient="row")
truth = pl.DataFrame({"column_0": [1, 3], "column_1": [2, 4]})
df = pl.DataFrame([[1, 2.0, "a"], [None, None, None]], orient="row")
truth = pl.DataFrame(
{"column_0": [1, None], "column_1": [2.0, None], "column_2": ["a", None]}
)
assert df.frame_equal(truth)

# TODO: Uncomment tests below when removing deprecation warning
Expand Down

0 comments on commit 98ccee4

Please sign in to comment.