tidypolars_extra.lubridate

Functions

as_date(x[, fmt])

Convert a string to a Date

as_datetime(x[, fmt])

Convert a string to a Datetime

ceiling_date(x[, unit, change_on_boundary])

Round date up to the nearest unit

days([n])

Create a duration of n days

difftime(x, y[, units])

Compute time differences in specified units

dt_round(x, rule, n)

Round the datetime

floor_date(x[, unit])

Round date down to the nearest unit

hour(x)

Extract the hour from a datetime

hours([n])

Create a duration of n hours

make_date([year, month, day])

Create a date object

make_datetime([year, month, day, hour, minute, second])

Create a datetime object

mday(x)

Extract the month day from a date from 1 to 31.

microseconds([n])

Create a duration of n microseconds

milliseconds([n])

Create a duration of n milliseconds

minute(x)

Extract the minute from a datetime

minutes([n])

Create a duration of n minutes

month(x)

Extract the month from a date

now()

Return the current datetime as a polars literal

quarter(x)

Extract the quarter from a date

second(x)

Extract the second from a datetime

seconds([n])

Create a duration of n seconds

today()

Return the current date as a polars literal

wday(x)

Extract the weekday from a date from sunday = 1 to saturday = 7.

week(x)

Extract the week from a date

weeks([n])

Create a duration of n weeks

yday(x)

Extract the year day from a date from 1 to 366.

year(x)

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))
tidypolars_extra.lubridate.yday(x)[source]

Extract the year day from a date from 1 to 366.

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(yearday = tp.yday(col('x')))
tidypolars_extra.lubridate.year(x)[source]

Extract the year from a date

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(year = tp.year(col('x')))