tidypolars_extra.lubridate¶
Functions¶
|
Convert a string to a Date |
|
Convert a string to a Datetime |
|
Round date up to the nearest unit |
|
Create a duration of n days |
|
Compute time differences in specified units |
|
Round the datetime |
|
Round date down to the nearest unit |
|
Extract the hour from a datetime |
|
Create a duration of n hours |
|
Create a date object |
|
Create a datetime object |
|
Extract the month day from a date from 1 to 31. |
|
Create a duration of n microseconds |
|
Create a duration of n milliseconds |
|
Extract the minute from a datetime |
|
Create a duration of n minutes |
|
Extract the month from a date |
|
Return the current datetime as a polars literal |
|
Extract the quarter from a date |
|
Extract the second from a datetime |
|
Create a duration of n seconds |
|
Return the current date as a polars literal |
|
Extract the weekday from a date from sunday = 1 to saturday = 7. |
|
Extract the week from a date |
|
Create a duration of n weeks |
|
Extract the year day from a date from 1 to 366. |
|
Extract the year from a date |
Module Contents¶
- tidypolars_extra.lubridate.as_date(x, fmt=None)[source]¶
Convert a string to a Date
- Parameters:
x (Expr, Series) – Column to operate on
fmt (str) – “yyyy-mm-dd”
Examples
>>> df = tp.tibble(x = ['2021-01-01', '2021-10-01']) >>> df.mutate(date_x = tp.as_date(col('x')))
- tidypolars_extra.lubridate.as_datetime(x, fmt=None)[source]¶
Convert a string to a Datetime
- Parameters:
x (Expr, Series) – Column to operate on
fmt (str) – “yyyy-mm-dd”
Examples
>>> df = tp.tibble(x = ['2021-01-01', '2021-10-01']) >>> df.mutate(date_x = tp.as_datetime(col('x')))
- tidypolars_extra.lubridate.ceiling_date(x, unit='month', change_on_boundary=False)[source]¶
Round date up to the nearest unit
- Parameters:
x (Expr, str) – Date/datetime column
unit (str) – Unit to round to: ‘year’, ‘month’, ‘week’, ‘day’, ‘hour’, ‘minute’, ‘second’
change_on_boundary (bool) – If False (default), dates already at a boundary are unchanged. If True, boundary dates are bumped to the next unit.
- Returns:
Date/datetime rounded up.
- Return type:
Expr
Examples
>>> df.mutate(month_end = tp.ceiling_date('date', 'month'))
- tidypolars_extra.lubridate.days(n=1)[source]¶
Create a duration of n days
- Parameters:
n (int) – Number of days
- Returns:
A duration literal.
- Return type:
Expr
Examples
>>> df.mutate(tomorrow = col('date') + tp.days(1))
- tidypolars_extra.lubridate.difftime(x, y, units='days')[source]¶
Compute time differences in specified units
- Parameters:
x (Expr, str) – Start date/datetime column
y (Expr, str) – End date/datetime column
units (str) – Units for the result: ‘days’, ‘hours’, ‘minutes’, ‘seconds’, ‘weeks’
- Returns:
Numeric expression with the time difference.
- Return type:
Expr
Examples
>>> df.mutate(diff = tp.difftime('date1', 'date2', units='days'))
- tidypolars_extra.lubridate.dt_round(x, rule, n)[source]¶
Round the datetime
- Parameters:
x (Expr, Series) – Column to operate on
rule (str) – Units of the downscaling operation. Any of:
"month","week","day","hour","minute","second".n (int) – Number of units (e.g. 5 “day”, 15 “minute”.
Examples
>>> df.mutate(monthday = tp.mday(col('x')))
- tidypolars_extra.lubridate.floor_date(x, unit='month')[source]¶
Round date down to the nearest unit
- Parameters:
x (Expr, str) – Date/datetime column
unit (str) – Unit to round to: ‘year’, ‘month’, ‘week’, ‘day’, ‘hour’, ‘minute’, ‘second’
- Returns:
Date/datetime rounded down.
- Return type:
Expr
Examples
>>> df.mutate(month_start = tp.floor_date('date', 'month'))
- tidypolars_extra.lubridate.hour(x)[source]¶
Extract the hour from a datetime
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(hour = tp.hour(col('x')))
- tidypolars_extra.lubridate.hours(n=1)[source]¶
Create a duration of n hours
- Parameters:
n (int) – Number of hours
- Returns:
A duration literal.
- Return type:
Expr
Examples
>>> df.mutate(later = col('datetime') + tp.hours(2))
- tidypolars_extra.lubridate.make_date(year=1970, month=1, day=1)[source]¶
Create a date object
- Parameters:
year (Expr, str, int) – Column or literal
month (Expr, str, int) – Column or literal
day (Expr, str, int) – Column or literal
Examples
>>> df.mutate(date = tp.make_date(2000, 1, 1))
- tidypolars_extra.lubridate.make_datetime(year=1970, month=1, day=1, hour=0, minute=0, second=0)[source]¶
Create a datetime object
- Parameters:
year (Expr, str, int) – Column or literal
month (Expr, str, int) – Column or literal
day (Expr, str, int) – Column or literal
hour (Expr, str, int) – Column or literal
minute (Expr, str, int) – Column or literal
second (Expr, str, int) – Column or literal
Examples
>>> df.mutate(date = tp.make_datetime(2000, 1, 1))
- tidypolars_extra.lubridate.mday(x)[source]¶
Extract the month day from a date from 1 to 31.
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(monthday = tp.mday(col('x')))
- tidypolars_extra.lubridate.microseconds(n=1)[source]¶
Create a duration of n microseconds
- Parameters:
n (int) – Number of microseconds
- Returns:
A duration literal.
- Return type:
Expr
- tidypolars_extra.lubridate.milliseconds(n=1)[source]¶
Create a duration of n milliseconds
- Parameters:
n (int) – Number of milliseconds
- Returns:
A duration literal.
- Return type:
Expr
- tidypolars_extra.lubridate.minute(x)[source]¶
Extract the minute from a datetime
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(hour = tp.minute(col('x')))
- tidypolars_extra.lubridate.minutes(n=1)[source]¶
Create a duration of n minutes
- Parameters:
n (int) – Number of minutes
- Returns:
A duration literal.
- Return type:
Expr
Examples
>>> df.mutate(later = col('datetime') + tp.minutes(30))
- tidypolars_extra.lubridate.month(x)[source]¶
Extract the month from a date
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(year = tp.month(col('x')))
- tidypolars_extra.lubridate.now()[source]¶
Return the current datetime as a polars literal
- Returns:
A literal expression with the current datetime.
- Return type:
Expr
Examples
>>> df.mutate(now = tp.now())
- tidypolars_extra.lubridate.quarter(x)[source]¶
Extract the quarter from a date
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(quarter = tp.quarter(col('x')))
- tidypolars_extra.lubridate.second(x)[source]¶
Extract the second from a datetime
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(hour = tp.minute(col('x')))
- tidypolars_extra.lubridate.seconds(n=1)[source]¶
Create a duration of n seconds
- Parameters:
n (int) – Number of seconds
- Returns:
A duration literal.
- Return type:
Expr
Examples
>>> df.mutate(later = col('datetime') + tp.seconds(10))
- tidypolars_extra.lubridate.today()[source]¶
Return the current date as a polars literal
- Returns:
A literal expression with today’s date.
- Return type:
Expr
Examples
>>> df.mutate(today = tp.today())
- tidypolars_extra.lubridate.wday(x)[source]¶
Extract the weekday from a date from sunday = 1 to saturday = 7.
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(weekday = tp.wday(col('x')))
- tidypolars_extra.lubridate.week(x)[source]¶
Extract the week from a date
- Parameters:
x (Expr, Series) – Column to operate on
Examples
>>> df.mutate(week = tp.week(col('x')))
- tidypolars_extra.lubridate.weeks(n=1)[source]¶
Create a duration of n weeks
- Parameters:
n (int) – Number of weeks
- Returns:
A duration literal.
- Return type:
Expr
Examples
>>> df.mutate(next_week = col('date') + tp.weeks(1))