Skip to content

Commit

Permalink
implement anyvalue -> datatype for all variants (#3340)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 9, 2022
1 parent ba44bfd commit 4e6fa11
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion polars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test:
--test-threads=2

integration-tests:
cargo t --all-features --test it
cargo t --all-features --test it -- --test-threads=2

miri:
# not tested on all features because miri does not support SIMD
Expand Down
4 changes: 1 addition & 3 deletions polars/polars-core/src/chunked_array/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ where

/// Trimmed down object safe polars object
pub trait PolarsObjectSafe: Any + Debug + Send + Sync + Display {
fn type_name(&self) -> &'static str
where
Self: Sized;
fn type_name(&self) -> &'static str;
}

/// Values need to implement this so that they can be stored into a Series and DataFrame
Expand Down
11 changes: 10 additions & 1 deletion polars/polars-core/src/frame/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,16 @@ impl<'a> From<&AnyValue<'a>> for DataType {
StructOwned(payload) => DataType::Struct(payload.1.to_vec()),
#[cfg(feature = "dtype-struct")]
Struct(_, fields) => DataType::Struct(fields.to_vec()),
av => panic!("{:?} not implemented", av),
#[cfg(feature = "dtype-duration")]
Duration(_, tu) => DataType::Duration(*tu),
UInt8(_) => DataType::UInt8,
UInt16(_) => DataType::UInt16,
Int8(_) => DataType::Int8,
Int16(_) => DataType::Int16,
#[cfg(feature = "dtype-categorical")]
Categorical(_, _) => DataType::Categorical(None),
#[cfg(feature = "object")]
Object(o) => DataType::Object(o.type_name()),
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,3 +873,21 @@ def test_datetime_strptime_patterns() -> None:
)["parsed"]
assert s.null_count() == 1
assert s[0] is None


def test_timedelta_from() -> None:
as_dict = {
"A": [1, 2],
"B": [timedelta(seconds=4633), timedelta(seconds=50)],
}
as_rows = [
{
"A": 1,
"B": timedelta(seconds=4633),
},
{
"A": 2,
"B": timedelta(seconds=50),
},
]
assert pl.DataFrame(as_dict).frame_equal(pl.DataFrame(as_rows))

0 comments on commit 4e6fa11

Please sign in to comment.