Ë L iH|ãó€—ddlmZddlmZmZmZddlmZmZer ddl m Z ddl m Z edd¬«Z Gd „d ee «Zy ) é)Ú annotations)Ú TYPE_CHECKINGÚGenericÚTypeVar)ÚExprKindÚExprNode)ÚExpr)ÚTimeUnitÚExprTr )ÚboundcóΗeZdZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z dd„Z dd „Z dd „Z dd „Z dd „Zdd „Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd d„Zd!d„Zd"d„Zy)#ÚExprDateTimeNamespacecó—||_y)N)Ú_expr)ÚselfÚexprs úV/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/narwhals/expr_dt.pyÚ__init__zExprDateTimeNamespace.__init__s €Øˆ ócóh—|jjttjd««S)uxExtract the date from underlying DateTime representation. Raises: NotImplementedError: If pandas default backend is being used. Examples: >>> from datetime import datetime >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... {"a": [datetime(2012, 1, 7, 10), datetime(2027, 12, 13)]} ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a").dt.date()).to_native() shape: (2, 1) ┌────────────┠│ a │ │ --- │ │ date │ ╞â•â•â•â•â•â•â•â•â•â•â•â•â•¡ │ 2012-01-07 │ │ 2027-12-13 │ └────────────┘ zdt.date©rÚ _append_noderrÚ ELEMENTWISE©rs rÚdatezExprDateTimeNamespace.dates&€ð2z‰z×&Ñ&¤x´×0DÑ0DÀiÓ'PÓQÐQrcóh—|jjttjd««S)u/Extract year from underlying DateTime representation. Returns the year number in the calendar date. Examples: >>> from datetime import datetime >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": [datetime(1978, 6, 1), datetime(2065, 1, 1)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a").dt.year().alias("year")) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a year| |0 1978-06-01 1978| |1 2065-01-01 2065| └──────────────────┘ zdt.yearrrs rÚyearzExprDateTimeNamespace.year-s&€ð,z‰z×&Ñ&¤x´×0DÑ0DÀiÓ'PÓQÐQrcóh—|jjttjd««S)aÅExtract month from underlying DateTime representation. Returns the month number starting from 1. The return value ranges from 1 to 12. Examples: >>> from datetime import datetime >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"a": [datetime(1978, 6, 1), datetime(2065, 1, 1)]}) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a").dt.month().alias("month")).to_native() pyarrow.Table a: timestamp[us] month: int64 ---- a: [[1978-06-01 00:00:00.000000,2065-01-01 00:00:00.000000]] month: [[6,1]] zdt.monthrrs rÚmonthzExprDateTimeNamespace.monthEs&€ð&z‰z×&Ñ&¤x´×0DÑ0DÀjÓ'QÓRÐRrcóh—|jjttjd««S)aæExtract day from underlying DateTime representation. Returns the day of month starting from 1. The return value ranges from 1 to 31. (The last day of month differs by months.) Examples: >>> from datetime import datetime >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"a": [datetime(1978, 6, 1), datetime(2065, 1, 1)]}) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a").dt.day().alias("day")).to_native() pyarrow.Table a: timestamp[us] day: int64 ---- a: [[1978-06-01 00:00:00.000000,2065-01-01 00:00:00.000000]] day: [[1,1]] zdt.dayrrs rÚdayzExprDateTimeNamespace.dayZs&€ð&z‰z×&Ñ&¤x´×0DÑ0DÀhÓ'OÓPÐPrcóh—|jjttjd««S)u“Extract hour from underlying DateTime representation. Returns the hour number from 0 to 23. Examples: >>> from datetime import datetime >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... {"a": [datetime(1978, 1, 1, 1), datetime(2065, 1, 1, 10)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a").dt.hour().alias("hour")) ┌──────────────────────────────┠| Narwhals DataFrame | |------------------------------| |shape: (2, 2) | |┌─────────────────────┬──────â”| |│ a ┆ hour │| |│ --- ┆ --- │| |│ datetime[μs] ┆ i8 │| |╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•¡| |│ 1978-01-01 01:00:00 ┆ 1 │| |│ 2065-01-01 10:00:00 ┆ 10 │| |└─────────────────────┴──────┘| └──────────────────────────────┘ zdt.hourrrs rÚhourzExprDateTimeNamespace.houros&€ð8z‰z×&Ñ&¤x´×0DÑ0DÀiÓ'PÓQÐQrcóh—|jjttjd««S)a‘Extract minutes from underlying DateTime representation. Returns the minute number from 0 to 59. Examples: >>> from datetime import datetime >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": [datetime(1978, 1, 1, 1, 1), datetime(2065, 1, 1, 10, 20)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a").dt.minute().alias("minute")).to_native() a minute 0 1978-01-01 01:01:00 1 1 2065-01-01 10:20:00 20 z dt.minuterrs rÚminutezExprDateTimeNamespace.minutes&€ð$z‰z×&Ñ&¤x´×0DÑ0DÀkÓ'RÓSÐSrcóh—|jjttjd««S)a/Extract seconds from underlying DateTime representation. Examples: >>> from datetime import datetime >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table( ... { ... "a": [ ... datetime(1978, 1, 1, 1, 1, 1), ... datetime(2065, 1, 1, 10, 20, 30), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a").dt.second().alias("second")).to_native() pyarrow.Table a: timestamp[us] second: int64 ---- a: [[1978-01-01 01:01:01.000000,2065-01-01 10:20:30.000000]] second: [[1,30]] z dt.secondrrs rÚsecondzExprDateTimeNamespace.second¡s&€ð0z‰z×&Ñ&¤x´×0DÑ0DÀkÓ'RÓSÐSrcóh—|jjttjd««S)axExtract milliseconds from underlying DateTime representation. Examples: >>> from datetime import datetime >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table( ... { ... "a": [ ... datetime(1978, 1, 1, 1, 1, 1, 0), ... datetime(2065, 1, 1, 10, 20, 30, 67000), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").dt.millisecond().alias("millisecond") ... ).to_native() pyarrow.Table a: timestamp[us] millisecond: int64 ---- a: [[1978-01-01 01:01:01.000000,2065-01-01 10:20:30.067000]] millisecond: [[0,67]] zdt.millisecondrrs rÚ millisecondz!ExprDateTimeNamespace.millisecond»ó'€ð4z‰z×&Ñ&¤x´×0DÑ0DÐFVÓ'WÓXÐXrcóh—|jjttjd««S)a{Extract microseconds from underlying DateTime representation. Examples: >>> from datetime import datetime >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table( ... { ... "a": [ ... datetime(1978, 1, 1, 1, 1, 1, 0), ... datetime(2065, 1, 1, 10, 20, 30, 67000), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").dt.microsecond().alias("microsecond") ... ).to_native() pyarrow.Table a: timestamp[us] microsecond: int64 ---- a: [[1978-01-01 01:01:01.000000,2065-01-01 10:20:30.067000]] microsecond: [[0,67000]] zdt.microsecondrrs rÚ microsecondz!ExprDateTimeNamespace.microsecond×r*rcóh—|jjttjd««S)ayExtract Nanoseconds from underlying DateTime representation. Examples: >>> from datetime import datetime >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table( ... { ... "a": [ ... datetime(1978, 1, 1, 1, 1, 1, 0), ... datetime(2065, 1, 1, 10, 20, 30, 67000), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").dt.nanosecond().alias("nanosecond") ... ).to_native() pyarrow.Table a: timestamp[us] nanosecond: int64 ---- a: [[1978-01-01 01:01:01.000000,2065-01-01 10:20:30.067000]] nanosecond: [[0,67000000]] z dt.nanosecondrrs rÚ nanosecondz ExprDateTimeNamespace.nanosecondós&€ð4z‰z×&Ñ&¤x´×0DÑ0DÀoÓ'VÓWÐWrcóh—|jjttjd««S)u=Get ordinal day. Examples: >>> from datetime import datetime >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": [datetime(2020, 1, 1), datetime(2020, 8, 3)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(a_ordinal_day=nw.col("a").dt.ordinal_day()) ┌───────────────────────────┠| Narwhals DataFrame | |---------------------------| | a a_ordinal_day| |0 2020-01-01 1| |1 2020-08-03 216| └───────────────────────────┘ zdt.ordinal_dayrrs rÚ ordinal_dayz!ExprDateTimeNamespace.ordinal_days'€ð(z‰z×&Ñ&¤x´×0DÑ0DÐFVÓ'WÓXÐXrcóh—|jjttjd««S)upExtract the week day from the underlying Date representation. Note that Monday = 1 and Sunday = 7. Examples: >>> from datetime import datetime >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": [datetime(2020, 1, 1), datetime(2020, 8, 3)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(a_week_day=nw.col("a").dt.weekday()) ┌────────────────────────┠| Narwhals DataFrame | |------------------------| | a a_week_day| |0 2020-01-01 3| |1 2020-08-03 1| └────────────────────────┘ z dt.weekdayrrs rÚweekdayzExprDateTimeNamespace.weekday%s&€ð,z‰z×&Ñ&¤x´×0DÑ0DÀlÓ'SÓTÐTrcóh—|jjttjd««S)ubGet total minutes. Notes: The function outputs the total minutes in the int dtype by default, however, pandas may change the dtype to float when there are missing values, consider using `fill_null()` and `cast` in this case. Examples: >>> from datetime import timedelta >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... {"a": [timedelta(minutes=10), timedelta(minutes=20, seconds=40)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_total_minutes=nw.col("a").dt.total_minutes() ... ).to_native() shape: (2, 2) ┌──────────────┬─────────────────┠│ a ┆ a_total_minutes │ │ --- ┆ --- │ │ duration[μs] ┆ i64 │ ╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡ │ 10m ┆ 10 │ │ 20m 40s ┆ 20 │ └──────────────┴─────────────────┘ zdt.total_minutesrrs rÚ total_minutesz#ExprDateTimeNamespace.total_minutes=ó'€ð:z‰z×&Ñ&¤x´×0DÑ0DÐFXÓ'YÓZÐZrcóh—|jjttjd««S)ugGet total seconds. Notes: The function outputs the total seconds in the int dtype by default, however, pandas may change the dtype to float when there are missing values, consider using `fill_null()` and `cast` in this case. Examples: >>> from datetime import timedelta >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... {"a": [timedelta(seconds=10), timedelta(seconds=20, milliseconds=40)]} ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_total_seconds=nw.col("a").dt.total_seconds() ... ).to_native() shape: (2, 2) ┌──────────────┬─────────────────┠│ a ┆ a_total_seconds │ │ --- ┆ --- │ │ duration[μs] ┆ i64 │ ╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡ │ 10s ┆ 10 │ │ 20s 40ms ┆ 20 │ └──────────────┴─────────────────┘ zdt.total_secondsrrs rÚ total_secondsz#ExprDateTimeNamespace.total_seconds\r5rcóh—|jjttjd««S)uMGet total milliseconds. Notes: The function outputs the total milliseconds in the int dtype by default, however, pandas may change the dtype to float when there are missing values, consider using `fill_null()` and `cast` in this case. Examples: >>> from datetime import timedelta >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... { ... "a": [ ... timedelta(milliseconds=10), ... timedelta(milliseconds=20, microseconds=40), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_total_milliseconds=nw.col("a").dt.total_milliseconds() ... ).to_native() shape: (2, 2) ┌──────────────┬──────────────────────┠│ a ┆ a_total_milliseconds │ │ --- ┆ --- │ │ duration[μs] ┆ i64 │ ╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡ │ 10ms ┆ 10 │ │ 20040µs ┆ 20 │ └──────────────┴──────────────────────┘ zdt.total_millisecondsrrs rÚtotal_millisecondsz(ExprDateTimeNamespace.total_milliseconds{s-€ðDz‰z×&Ñ&Ü ”X×)Ñ)Ð+BÓ Có ð rcóh—|jjttjd««S)a>Get total microseconds. Notes: The function outputs the total microseconds in the int dtype by default, however, pandas may change the dtype to float when there are missing values, consider using `fill_null()` and `cast` in this case. Examples: >>> from datetime import timedelta >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table( ... { ... "a": [ ... timedelta(microseconds=10), ... timedelta(milliseconds=1, microseconds=200), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_total_microseconds=nw.col("a").dt.total_microseconds() ... ).to_native() pyarrow.Table a: duration[us] a_total_microseconds: int64 ---- a: [[10,1200]] a_total_microseconds: [[10,1200]] zdt.total_microsecondsrrs rÚtotal_microsecondsz(ExprDateTimeNamespace.total_microseconds¡s,€ð>z‰z×&Ñ&Ü ”X×)Ñ)Ð+BÓ Có ð rcóh—|jjttjd««S)a®Get total nanoseconds. Notes: The function outputs the total nanoseconds in the int dtype by default, however, pandas may change the dtype to float when there are missing values, consider using `fill_null()` and `cast` in this case. Examples: >>> from datetime import timedelta >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... { ... "a": pd.to_datetime( ... [ ... "2024-01-01 00:00:00.000000001", ... "2024-01-01 00:00:00.000000002", ... ] ... ) ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_diff_total_nanoseconds=nw.col("a").diff().dt.total_nanoseconds() ... ).to_native() a a_diff_total_nanoseconds 0 2024-01-01 00:00:00.000000001 NaN 1 2024-01-01 00:00:00.000000002 1.0 zdt.total_nanosecondsrrs rÚtotal_nanosecondsz'ExprDateTimeNamespace.total_nanosecondsÄs,€ð<z‰z×&Ñ&Ü ”X×)Ñ)Ð+AÓ Bó ð rcól—|jjttjd|¬««S)uÇ Convert a Date/Time/Datetime column into a String column with the given format. Arguments: format: Format to format temporal column with. Notes: Unfortunately, different libraries interpret format directives a bit differently. - Chrono, the library used by Polars, uses `"%.f"` for fractional seconds, whereas pandas and Python stdlib use `".%f"`. - PyArrow interprets `"%S"` as "seconds, including fractional seconds" whereas most other tools interpret it as "just seconds, as 2 digits". --- Therefore, we make the following adjustments. - for pandas-like libraries, we replace `"%S.%f"` with `"%S%.f"`. - for PyArrow, we replace `"%S.%f"` with `"%S"`. --- Workarounds like these don't make us happy, and we try to avoid them as much as possible, but here we feel like it's the best compromise. If you just want to format a date/datetime Series as a local datetime string, and have it work as consistently as possible across libraries, we suggest using: - `"%Y-%m-%dT%H:%M:%S%.f"` for datetimes - `"%Y-%m-%d"` for dates --- Though note that, even then, different tools may return a different number of trailing zeros. Nonetheless, this is probably consistent enough for most applications. If you have an application where this is not enough, please open an issue and let us know. Examples: >>> from datetime import datetime >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... {"a": [datetime(2020, 3, 1), datetime(2020, 5, 1)]} ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a").dt.to_string("%Y/%m/%d %H:%M:%S")) ┌───────────────────────┠| Narwhals DataFrame | |-----------------------| |shape: (2, 1) | |┌─────────────────────â”| |│ a │| |│ --- │| |│ str │| |╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ 2020/03/01 00:00:00 │| |│ 2020/05/01 00:00:00 │| |└─────────────────────┘| └───────────────────────┘ z dt.to_string)Úformatr)rr?s rÚ to_stringzExprDateTimeNamespace.to_stringæs.€ðxz‰z×&Ñ&Ü ”X×)Ñ)¨>À&Ô Ió ð rcól—|jjttjd|¬««S)aReplace time zone. Arguments: time_zone: Target time zone. Examples: >>> from datetime import datetime, timezone >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... { ... "a": [ ... datetime(2024, 1, 1, tzinfo=timezone.utc), ... datetime(2024, 1, 2, tzinfo=timezone.utc), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a").dt.replace_time_zone("Asia/Kathmandu")).to_native() a 0 2024-01-01 00:00:00+05:45 1 2024-01-02 00:00:00+05:45 zdt.replace_time_zone©Ú time_zoner)rrCs rÚreplace_time_zonez'ExprDateTimeNamespace.replace_time_zone&s.€ð0z‰z×&Ñ&Ü ”X×)Ñ)Ð+AÈYÔ Wó ð rcóŠ—|€ d}t|«‚|jjttj d|¬««S)a—Convert to a new time zone. If converting from a time-zone-naive column, then conversion happens as if converting from UTC. Arguments: time_zone: Target time zone. Examples: >>> from datetime import datetime, timezone >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... { ... "a": [ ... datetime(2024, 1, 1, tzinfo=timezone.utc), ... datetime(2024, 1, 2, tzinfo=timezone.utc), ... ] ... } ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a").dt.convert_time_zone("Asia/Kathmandu")).to_native() a 0 2024-01-01 05:45:00+05:45 1 2024-01-02 05:45:00+05:45 z…Target `time_zone` cannot be `None` in `convert_time_zone`. Please use `replace_time_zone(None)` if you want to remove the time zone.zdt.convert_time_zonerB)Ú TypeErrorrrrrr)rrCÚmsgs rÚconvert_time_zonez'ExprDateTimeNamespace.convert_time_zoneBsF€ð6 Ð ðZˆCܘC“.Ð Øz‰z×&Ñ&Ü ”X×)Ñ)Ð+AÈYÔ Wó ð rcó–—|dvrd|›d}t|«‚|jjttj d|¬««S)u³Return a timestamp in the given time unit. Arguments: time_unit: One of - 'ns': nanosecond. - 'us': microsecond. - 'ms': millisecond. Examples: >>> from datetime import date >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"date": [date(2001, 1, 1), None]}) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("date").dt.timestamp("ms").alias("timestamp_ms")) ┌─────────────────────────────┠| Narwhals DataFrame | |-----------------------------| |shape: (2, 2) | |┌────────────┬──────────────â”| |│ date ┆ timestamp_ms │| |│ --- ┆ --- │| |│ date ┆ i64 │| |╞â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ 2001-01-01 ┆ 978307200000 │| |│ null ┆ null │| |└────────────┴──────────────┘| └─────────────────────────────┘ >ÚmsÚnsÚusz=invalid `time_unit` Expected one of {'ns', 'us', 'ms'}, got ú.z dt.timestamp)Ú time_unit)Ú ValueErrorrrrrr)rrNrGs rÚ timestampzExprDateTimeNamespace.timestampdsZ€ð< Ð.Ñ .ðAØAJÀ ÈQðPð ô˜S“/Ð !Øz‰z×&Ñ&Ü ”X×)Ñ)¨>ÀYÔ Oó ð rcól—|jjttjd|¬««S)uiDivide the date/datetime range into buckets. Arguments: every: Length of bucket. Must be of form ``, where `multiple` is a positive integer and `unit` is one of - 'ns': nanosecond. - 'us': microsecond. - 'ms': millisecond. - 's': second. - 'm': minute. - 'h': hour. - 'd': day. - 'mo': month. - 'q': quarter. - 'y': year. Examples: >>> from datetime import datetime >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"datetime": [datetime(2021, 3, 1, 12, 34)]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("datetime").dt.truncate("1h").alias("datetime_trunc") ... ) ┌─────────────────────────────────────────────┠| Narwhals DataFrame | |---------------------------------------------| |shape: (1, 2) | |┌─────────────────────┬─────────────────────â”| |│ datetime ┆ datetime_trunc │| |│ --- ┆ --- │| |│ datetime[μs] ┆ datetime[μs] │| |╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ 2021-03-01 12:34:00 ┆ 2021-03-01 12:00:00 │| |└─────────────────────┴─────────────────────┘| └─────────────────────────────────────────────┘ z dt.truncate)Úeveryr)rrRs rÚtruncatezExprDateTimeNamespace.truncateŒs.€ðPz‰z×&Ñ&Ü ”X×)Ñ)¨=ÀÔ Fó ð rcól—|jjttjd|¬««S)u“Offset this date by a relative time offset. Arguments: by: The offset. Must be of form ``, where `multiple` is a positive integer and `unit` is one of - 'ns': nanosecond. - 'us': microsecond. - 'ms': millisecond. - 's': second. - 'm': minute. - 'h': hour. - 'd': day. - 'mo': month. - 'q': quarter. - 'y': year. Examples: >>> from datetime import datetime >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"datetime": [datetime(2021, 3, 1, 12, 34)]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("datetime").dt.offset_by("1h").alias("datetime_offset_by_1h") ... ) ┌───────────────────────────────────────────────┠| Narwhals DataFrame | |-----------------------------------------------| |shape: (1, 2) | |┌─────────────────────┬───────────────────────â”| |│ datetime ┆ datetime_offset_by_1h │| |│ --- ┆ --- │| |│ datetime[μs] ┆ datetime[μs] │| |╞â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ 2021-03-01 12:34:00 ┆ 2021-03-01 13:34:00 │| |└─────────────────────┴───────────────────────┘| └───────────────────────────────────────────────┘ z dt.offset_by)Úbyr)rrUs rÚ offset_byzExprDateTimeNamespace.offset_by¸s.€ðPz‰z×&Ñ&Ü ”X×)Ñ)¨>¸bÔ Aó ð rN)rr ÚreturnÚNone)rWr )r?ÚstrrWr )rCz str | NonerWr )rCrYrWr )rL)rNr rWr )rRrYrWr )rUrYrWr )Ú__name__Ú __module__Ú __qualname__rrrrr!r#r%r'r)r,r.r0r2r4r7r9r;r=r@rDrHrPrSrV©rrrrs„óóRó6Ró0Só*Qó*Ró<Tó(Tó4Yó8Yó8Xó8Yó,Uó0[ó>[ó>$ óL! óF  óD> ó@ ó8  ôD& óP* ôX* rrN)Ú __future__rÚtypingrrrÚnarwhals._expression_parsingrrÚ narwhals.exprr Únarwhals.typingr r rr]rrúrcs8ðÝ"ç2Ñ2ç;áÝ"Ý(á˜vÔ&€ôT  ˜G E™NõT  r