Skip to content

Commit

Permalink
improve str -> date cast error message and fix wrong docstring (#1691)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 7, 2021
1 parent 2c66829 commit a230d36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion polars/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ impl Series {
if self.null_count() != s.null_count() {
Err(PolarsError::ComputeError(
format!(
"strict conversion of cast from {:?} to {:?} failed. consider non-strict cast.",
"strict conversion of cast from {:?} to {:?} failed. consider non-strict cast.\n
If you were trying to cast Utf8 to Date,Time,Datetime, consider using `strptime`",
self.dtype(),
data_type
)
Expand Down
20 changes: 10 additions & 10 deletions py-polars/polars/eager/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,21 +1655,21 @@ def cast(self, dtype: Type[DataType], strict: bool = True) -> "Series":
Examples
--------
>>> s = pl.Series("a", ["2020-01-01", "2020-01-02", "2020-01-03"])
>>> s = pl.Series("a", [True, False, True])
shape: (3,)
Series: 'a' [str]
Series: 'a' [bool]
[
"2020-01-01"
"2020-01-02"
"2020-01-03"
true
false
true
]
>>> s.cast(pl.datatypes.Date)
>>> s.cast(pl.UInt32)
shape: (3,)
Series: 'a' [date]
Series: 'a' [u32]
[
2020-01-01
2020-01-02
2020-01-03
1
0
1
]
"""
Expand Down

0 comments on commit a230d36

Please sign in to comment.