-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datetime localization support #12341
Comments
use chrono::prelude::*;
fn main() {
let dt = Utc.with_ymd_and_hms(2023, 11, 8, 19, 5, 7).unwrap();
let out = dt
.format_localized("%A, %d %B %Y", Locale::uk_UA)
.to_string();
dbg!(out);
} [src/main.rs:7] out = "середа, 08 листопада 2023" I'm not sure if enabling it has been previously discussed? Line 34 in 30e4471
|
I think this is a reasonable request In the meantime, rather than In [43]: def localize_ukraine(expr):
...: return (
...: expr
...: .str.replace('Wednesday', 'середа')
...: .str.replace('November', 'листопада') # put other replacements below
...: )
...:
In [44]: localize_ukraine(date_1.dt.strftime('%A, %d %B %Y'))
Out[44]:
shape: (1,)
Series: '' [str]
[
"середа, 08 листопада 2023"
] would work better for you |
Instead of trying to do string replacements to work around the locale issue, an alternate approach would be to use pyarrow's strftime which I put in the SO answer |
@cmdlineluser I comlpiled Where am I wrong? |
Building chrono with that feature gives access to the A way to call |
Hi @ap-Codkelden - I'm adding this to In [1]: import polars as pl
...: import polars_xdt # noqa: F401
...:
...: from datetime import datetime
...:
...: df = pl.DataFrame(
...: {
...: "date_col": [datetime(2024, 8, 24), datetime(2024, 10, 1)],
...: }
...: )
...: df.with_columns(result=pl.col("date_col").xdt.format_localized("%A, %d %B %Y", 'uk_UA'))
Out[1]:
shape: (2, 2)
┌─────────────────────┬──────────────────────────┐
│ date_col ┆ result │
│ --- ┆ --- │
│ datetime[μs] ┆ str │
╞═════════════════════╪══════════════════════════╡
│ 2024-08-24 00:00:00 ┆ субота, 24 серпня 2024 │
│ 2024-10-01 00:00:00 ┆ вівторок, 01 жовтня 2024 │
└─────────────────────┴──────────────────────────┘ Just fixing up a couple of things, hoping to make a new release with this today |
Released, Closing then, but thanks for the request! And thanks @cmdlineluser for finding |
Description
By using Pandas, I can get localized strings from dates with
pandas.Series.dt.strftime
, e.g.:However, this feature is currently absent in Polars (as of ver. 0.19.12).
Certainly, I can use lambda or a regular custom function to do that,
but I'd like to use a more native mechanism.
The text was updated successfully, but these errors were encountered: