polars icon indicating copy to clipboard operation
polars copied to clipboard

Trait `NamedFrom<Vec<[AnyEnum]>>` isn't implemented in `Series`

Open pauliesnug opened this issue 1 year ago • 3 comments

Checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of Polars.

Reproducible example

Install pandas and create a new Enum to be used in a Series:

use polars::prelude::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AnyEnum {
	MyEnumValue,
	OtherEnumValue,
}

#[derive(Debug, Clone, Copy)]
pub struct AnyStruct {
	pub _enum: AnyEnum,
}

fn main(data: Vec<AnyStruct>) -> Result<DataFrame> {
	let enums = Series::new("enum", data.iter().map(|d| d._enum).collect());
	Ok(DataFrame::new(vec![enums])
}

Log output

error: the trait bound `polars::prelude::Series: polars::prelude::NamedFrom<Vec<AnyEnum>, _>` is not satisfied
label: the trait `polars::prelude::NamedFrom<Vec<AnyEnum>, _>` is not implemented for `polars::prelude::Series`

Issue description

I'm also using ndarray and the use case for this is to have a user-input array with type hints provided by the enum which is then formatted into a DataFrame in the processing logic.

Expected behavior

I expected it to treat an enum like any other object and add it to the DataFrame series.

Installed versions

polars = { git = "https://github.com/pola-rs/polars", features = [
	"lazy", "ndarray", "temporal", "timezones", "serde",
	"serde-lazy", "json", "dtype-datetime", "dtype-categorical",
	"dtype-struct", "object"
] }

pauliesnug avatar Jan 06 '24 17:01 pauliesnug

Trait NamedFrom<Vec<[AnyEnum]>> isn't implemented in Series

Of course it isn't? You just defined AnyEnum. How should we have implemented that. You should take out then values that polars knows. AnyEnum isn't known to polars.

ritchie46 avatar Jan 06 '24 17:01 ritchie46

Of course it isn't? You just defined AnyEnum. How should we have implemented that. You should take out then values that polars knows. AnyEnum isn't known to polars.

Sorry, I should have been more clear.... I want to be able to add the enum dtype to AnyType.

pauliesnug avatar Jan 06 '24 19:01 pauliesnug

I don't really understand. The AnyType is a closed enum. How would that work?

ritchie46 avatar Jan 07 '24 09:01 ritchie46