Skip to content

Commit

Permalink
Allow extract int from str anyvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Jan 19, 2024
1 parent 1d434cc commit 601cd5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/polars-core/src/datatypes/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ impl<'a> AnyValue<'a> {
NumCast::from(0)
}
},
String(v) => NumCast::from((*v).parse::<i64>().ok()?),
_ => None,
}
}
Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -3369,6 +3369,13 @@ def test_from_dicts_undeclared_column_dtype() -> None:
assert result.schema == {"x": pl.Null}


def test_from_dicts_with_override() -> None:
data = [{'a': '1', 'b': '2'}, {'a':1, 'b':2}]
override = {'a': pl.Int32, 'b': pl.UInt8}
result = pl.from_dicts(data, schema_overrides=override)
assert result.schema == {"a": pl.Int32, "b": pl.UInt8}


def test_from_records_u64_12329() -> None:
s = pl.from_records([{"a": 9908227375760408577}])
assert s.dtypes == [pl.UInt64]
Expand Down

0 comments on commit 601cd5a

Please sign in to comment.