PyLegendStrictDate

__eq__

PyLegendPrimitive.__eq__(other)[source]

Test element-wise equality (==).

Compare this expression against another primitive value or expression. Returns a boolean expression that is True where the values are equal.

Parameters:

other (Union[int, float, bool, str, date, datetime, Decimal, PyLegendPrimitive]) – The value or expression to compare against.

Returns:

A boolean expression representing the equality test.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported primitive type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Filter rows where Ship Name equals a literal
frame[frame["Ship Name"] == "Around the Horn"].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10355 1996-11-15 1996-12-13 1996-11-20 Around the Horn
1 10383 1996-12-16 1997-01-13 1996-12-18 Around the Horn
2 10453 1997-02-21 1997-03-21 1997-02-26 Around the Horn

__ge__

PyLegendDate.__ge__(other)[source]

Date greater than or equal (>=).

Parameters:

other (Union[date, datetime, PyLegendStrictDate, PyLegendDateTime, PyLegendDate]) – The right-hand operand.

Return type:

PyLegendBoolean

Examples

Download Interactive Notebook

import pylegend
from datetime import date
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Shipped Date"] >= date(1998, 4, 1)].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10924 1998-03-04 1998-04-01 1998-04-08 Berglunds snabbköp
1 10927 1998-03-05 1998-04-02 1998-04-08 La corne d'abondance
2 10951 1998-03-16 1998-04-27 1998-04-07 Richter Supermarkt

__gt__

PyLegendDate.__gt__(other)[source]

Date greater than (>).

Parameters:

other (Union[date, datetime, PyLegendStrictDate, PyLegendDateTime, PyLegendDate]) – The right-hand operand.

Return type:

PyLegendBoolean

Examples

Download Interactive Notebook

import pylegend
from datetime import date
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Shipped Date"] > date(1998, 4, 1)].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10924 1998-03-04 1998-04-01 1998-04-08 Berglunds snabbköp
1 10927 1998-03-05 1998-04-02 1998-04-08 La corne d'abondance
2 10951 1998-03-16 1998-04-27 1998-04-07 Richter Supermarkt

__le__

PyLegendDate.__le__(other)[source]

Date less than or equal (<=).

Parameters:

other (Union[date, datetime, PyLegendStrictDate, PyLegendDateTime, PyLegendDate]) – The right-hand operand.

Return type:

PyLegendBoolean

Examples

Download Interactive Notebook

import pylegend
from datetime import date
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Shipped Date"] <= date(1996, 8, 1)].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

__lt__

PyLegendDate.__lt__(other)[source]

Date less than (<).

Parameters:

other (Union[date, datetime, PyLegendStrictDate, PyLegendDateTime, PyLegendDate]) – The right-hand operand.

Return type:

PyLegendBoolean

Examples

Download Interactive Notebook

import pylegend
from datetime import date
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Shipped Date"] < date(1996, 8, 1)].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

__ne__

PyLegendPrimitive.__ne__(other)[source]

Test element-wise inequality (!=).

Compare this expression against another primitive value or expression. Returns a boolean expression that is True where the values differ.

Parameters:

other (Union[int, float, bool, str, date, datetime, Decimal, PyLegendPrimitive]) – The value or expression to compare against.

Returns:

A boolean expression representing the inequality test.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported primitive type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Filter rows where Ship Name is not a specific value
frame[frame["Ship Name"] != "Ship1"].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

adjust

PyLegendDate.adjust(number, duration_unit)[source]

Alias for timedelta() that also accepts a DurationUnit enum.

Parameters:
  • number (Union[int, PyLegendInteger]) – How many units to shift.

  • duration_unit (Union[str, DurationUnit]) – The duration unit.

Return type:

PyLegendDate

Examples

Download Interactive Notebook

import pylegend
from pylegend.core.language.shared.operations.date_operation_expressions import DurationUnit
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["plus_1m"] = frame["Shipped Date"].adjust(1, DurationUnit.MONTHS)
frame[["Shipped Date", "plus_1m"]].head(3).to_pandas()
Shipped Date plus_1m
0 1996-07-16 1996-08-16
1 1996-07-10 1996-08-10
2 1996-07-12 1996-08-12

date_diff

PyLegendDate.date_diff(other, duration_unit)[source]

Alias for diff().

Parameters:
  • other (Union[date, datetime, PyLegendStrictDate, PyLegendDateTime, PyLegendDate]) – The date to subtract.

  • duration_unit (str) – The unit for the result.

Return type:

PyLegendInteger

date_part

PyLegendDate.date_part()[source]

Extract the date portion, discarding any time component.

Return type:

PyLegendStrictDate

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES")
frame["dt"] = frame["ts"].date_part()
frame[["ts", "dt"]].head(3).to_pandas()
ts dt
0 1996-07-16 14:35:00+00:00 1996-07-16
1 1996-07-10 14:35:00+00:00 1996-07-10
2 1996-07-12 14:35:00+00:00 1996-07-12

datePart

PyLegendDate.datePart()[source]

Alias for date_part().

Return type:

PyLegendStrictDate

day

PyLegendDate.day()[source]

Extract the day of the month (1–31).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["d"] = frame["Shipped Date"].day()
frame[["Shipped Date", "d"]].head(3).to_pandas()
Shipped Date d
0 1996-07-16 16
1 1996-07-10 10
2 1996-07-12 12

day_of_week

PyLegendDate.day_of_week()[source]

Extract the day of the week (1 = Monday … 7 = Sunday).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["dow"] = frame["Shipped Date"].day_of_week()
frame[["Shipped Date", "dow"]].head(3).to_pandas()
Shipped Date dow
0 1996-07-16 3
1 1996-07-10 4
2 1996-07-12 6

day_of_year

PyLegendDate.day_of_year()[source]

Extract the day of the year (1–366).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["doy"] = frame["Shipped Date"].day_of_year()
frame[["Shipped Date", "doy"]].head(3).to_pandas()
Shipped Date doy
0 1996-07-16 198
1 1996-07-10 192
2 1996-07-12 194

dayOfMonth

PyLegendDate.dayOfMonth()[source]

Alias for day().

Return type:

PyLegendInteger

dayOfWeekNumber

PyLegendDate.dayOfWeekNumber()[source]

Alias for day_of_week().

Return type:

PyLegendInteger

diff

PyLegendDate.diff(other, duration_unit)[source]

Compute the difference between two dates in the given unit.

Parameters:
  • other (Union[date, datetime, PyLegendStrictDate, PyLegendDateTime, PyLegendDate]) – The date to subtract.

  • duration_unit (str) – The unit for the result (see timedelta() for allowed values).

Returns:

self other expressed in duration_unit.

Return type:

PyLegendInteger

Raises:
  • TypeError – If other is not a date expression or literal.

  • ValueError – If duration_unit is not a recognised unit.

Examples

Download Interactive Notebook

import pylegend
from datetime import date
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["lag"] = frame["Order Date"].diff(frame["Shipped Date"], "DAYS")
frame[["Shipped Date", "lag"]].head(3).to_pandas()
Shipped Date lag
0 1996-07-16 12
1 1996-07-10 5
2 1996-07-12 4

epoch_value

PyLegendDate.epoch_value()[source]

Seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["epoch"] = frame["Shipped Date"].epoch_value()
frame[["Shipped Date", "epoch"]].head(3).to_pandas()
Shipped Date epoch
0 1996-07-16 837475200
1 1996-07-10 836956800
2 1996-07-12 837129600

first_day_of_month

PyLegendDate.first_day_of_month()[source]

First day of the month for each date.

Returns:

A date set to the 1st of the same month.

Return type:

PyLegendDate

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["mo_start"] = frame["Shipped Date"].first_day_of_month()
frame[["Shipped Date", "mo_start"]].head(3).to_pandas()
Shipped Date mo_start
0 1996-07-16 1996-07-01
1 1996-07-10 1996-07-01
2 1996-07-12 1996-07-01

first_day_of_quarter

PyLegendDate.first_day_of_quarter()[source]

First day of the quarter for each date.

Returns:

A date set to the first day of the quarter.

Return type:

PyLegendDate

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["qtr_start"] = frame["Shipped Date"].first_day_of_quarter()
frame[["Shipped Date", "qtr_start"]].head(3).to_pandas()
Shipped Date qtr_start
0 1996-07-16 1996-07-01
1 1996-07-10 1996-07-01
2 1996-07-12 1996-07-01

first_day_of_week

PyLegendDate.first_day_of_week()[source]

First day of the ISO week for each date.

Returns:

A date set to the Monday of the same ISO week.

Return type:

PyLegendDate

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["wk_start"] = frame["Shipped Date"].first_day_of_week()
frame[["Shipped Date", "wk_start"]].head(3).to_pandas()
Shipped Date wk_start
0 1996-07-16 1996-07-14
1 1996-07-10 1996-07-07
2 1996-07-12 1996-07-07

first_day_of_year

PyLegendDate.first_day_of_year()[source]

First day of the year for each date.

Returns:

A date set to January 1 of the same year.

Return type:

PyLegendDate

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["yr_start"] = frame["Shipped Date"].first_day_of_year()
frame[["Shipped Date", "yr_start"]].head(3).to_pandas()
Shipped Date yr_start
0 1996-07-16 1996-01-01
1 1996-07-10 1996-01-01
2 1996-07-12 1996-01-01

first_hour_of_day

PyLegendDate.first_hour_of_day()[source]

First hour (midnight) of the day as a datetime.

Returns:

A datetime set to 00:00:00 of the same day.

Return type:

PyLegendDateTime

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["midnight"] = frame["ts"].first_hour_of_day()
frame[["ts", "midnight"]].head(3).to_pandas()
ts midnight
0 1996-07-16 14:35:22+00:00 1996-07-16
1 1996-07-10 14:35:22+00:00 1996-07-10
2 1996-07-12 14:35:22+00:00 1996-07-12

first_millisecond_of_second

PyLegendDate.first_millisecond_of_second()[source]

First millisecond of the second as a datetime.

Returns:

A datetime with milliseconds set to zero.

Return type:

PyLegendDateTime

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["sec_start"] = frame["ts"].first_millisecond_of_second()
frame[["ts", "sec_start"]].head(3).to_pandas()
ts sec_start
0 1996-07-16 14:35:22+00:00 1996-07-16 14:35:22+00:00
1 1996-07-10 14:35:22+00:00 1996-07-10 14:35:22+00:00
2 1996-07-12 14:35:22+00:00 1996-07-12 14:35:22+00:00

first_minute_of_hour

PyLegendDate.first_minute_of_hour()[source]

First minute of the hour as a datetime.

Returns:

A datetime with minutes and seconds set to zero.

Return type:

PyLegendDateTime

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["hr_start"] = frame["ts"].first_minute_of_hour()
frame[["ts", "hr_start"]].head(3).to_pandas()
ts hr_start
0 1996-07-16 14:35:22+00:00 1996-07-16 14:00:00+00:00
1 1996-07-10 14:35:22+00:00 1996-07-10 14:00:00+00:00
2 1996-07-12 14:35:22+00:00 1996-07-12 14:00:00+00:00

first_second_of_minute

PyLegendDate.first_second_of_minute()[source]

First second of the minute as a datetime.

Returns:

A datetime with seconds set to zero.

Return type:

PyLegendDateTime

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["min_start"] = frame["ts"].first_second_of_minute()
frame[["ts", "min_start"]].head(3).to_pandas()
ts min_start
0 1996-07-16 14:35:22+00:00 1996-07-16 14:35:00+00:00
1 1996-07-10 14:35:22+00:00 1996-07-10 14:35:00+00:00
2 1996-07-12 14:35:22+00:00 1996-07-12 14:35:00+00:00

firstDayOfMonth

PyLegendDate.firstDayOfMonth()[source]

Alias for first_day_of_month().

Return type:

PyLegendDate

firstDayOfQuarter

PyLegendDate.firstDayOfQuarter()[source]

Alias for first_day_of_quarter().

Return type:

PyLegendDate

firstDayOfWeek

PyLegendDate.firstDayOfWeek()[source]

Alias for first_day_of_week().

Return type:

PyLegendDate

firstDayOfYear

PyLegendDate.firstDayOfYear()[source]

Alias for first_day_of_year().

Return type:

PyLegendDate

hour

PyLegendDate.hour()[source]

Extract the hour (0–23).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["hr"] = frame["ts"].hour()
frame[["ts", "hr"]].head(3).to_pandas()
ts hr
0 1996-07-16 14:35:22+00:00 14
1 1996-07-10 14:35:22+00:00 14
2 1996-07-12 14:35:22+00:00 14

in_list

PyLegendPrimitive.in_list(lst)[source]

Test whether the value is contained in a list of values.

Returns a boolean expression equivalent to SQL IN (...).

Parameters:

lst (List[Union[int, float, bool, str, date, datetime, Decimal, PyLegendPrimitive]]) – A non-empty list of literal values or expressions to check membership against.

Returns:

True where the value matches any element in lst.

Return type:

PyLegendBoolean

Raises:
  • ValueError – If lst is not a list or is empty.

  • TypeError – If any element in lst is not a supported primitive type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Keep rows where Ship Name is one of several values
frame[
    frame["Ship Name"].in_list(["Hanari Carnes", "Victuailles en stock", "Suprêmes délices"])
].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes
1 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock
2 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices

is_empty

PyLegendPrimitive.is_empty()[source]

Test whether the value is null / empty.

Returns a boolean expression that is True where the underlying column value is NULL.

Returns:

True where the value is null.

Return type:

PyLegendBoolean

See also

is_not_empty

The inverse test.

is_null

Alias for is_empty.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Keep only rows where Ship Name is null
frame[frame["Shipped Date"].is_empty()].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 11008 1998-04-08 1998-05-06 NaT Ernst Handel
1 11019 1998-04-13 1998-05-11 NaT Rancho grande
2 11039 1998-04-21 1998-05-19 NaT LINO-Delicateses

is_not_empty

PyLegendPrimitive.is_not_empty()[source]

Test whether the value is not null / not empty.

Returns a boolean expression that is True where the underlying column value is not NULL.

Returns:

True where the value is not null.

Return type:

PyLegendBoolean

See also

is_empty

The inverse test.

is_not_null

Alias for is_not_empty.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Keep only rows where Ship Name is present
frame[frame["Ship Name"].is_not_empty()].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

is_not_null

PyLegendPrimitive.is_not_null()[source]

Test whether the value is not null.

Alias for is_not_empty().

Returns:

True where the value is not null.

Return type:

PyLegendBoolean

See also

is_not_empty

Canonical not-null-check method.

is_null

The inverse test.

is_null

PyLegendPrimitive.is_null()[source]

Test whether the value is null.

Alias for is_empty().

Returns:

True where the value is null.

Return type:

PyLegendBoolean

See also

is_empty

Canonical null-check method.

is_not_null

The inverse test.

minute

PyLegendDate.minute()[source]

Extract the minute (0–59).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["min"] = frame["ts"].minute()
frame[["ts", "min"]].head(3).to_pandas()
ts min
0 1996-07-16 14:35:22+00:00 35
1 1996-07-10 14:35:22+00:00 35
2 1996-07-12 14:35:22+00:00 35

month

PyLegendDate.month()[source]

Extract the month (1–12).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["mo"] = frame["Shipped Date"].month()
frame[["Shipped Date", "mo"]].head(3).to_pandas()
Shipped Date mo
0 1996-07-16 7
1 1996-07-10 7
2 1996-07-12 7

monthNumber

PyLegendDate.monthNumber()[source]

Alias for month().

Return type:

PyLegendInteger

quarter

PyLegendDate.quarter()[source]

Extract the quarter (1–4).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["qtr"] = frame["Shipped Date"].quarter()
frame[["Shipped Date", "qtr"]].head(3).to_pandas()
Shipped Date qtr
0 1996-07-16 3
1 1996-07-10 3
2 1996-07-12 3

quarterNumber

PyLegendDate.quarterNumber()[source]

Alias for quarter().

Return type:

PyLegendInteger

second

PyLegendDate.second()[source]

Extract the second (0–59).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ts"] = frame["Shipped Date"].first_hour_of_day().timedelta(14, "HOURS").timedelta(35, "MINUTES").timedelta(22, "SECONDS")
frame["sec"] = frame["ts"].second()
frame[["ts", "sec"]].head(3).to_pandas()
ts sec
0 1996-07-16 14:35:22+00:00 22
1 1996-07-10 14:35:22+00:00 22
2 1996-07-12 14:35:22+00:00 22

time_bucket

PyLegendStrictDate.time_bucket(quantity, duration_unit)[source]

Group the date into fixed-width buckets.

Returns the start of the bucket that each date falls into. Useful for time-series aggregation at a coarser granularity.

Parameters:
  • quantity (Union[int, PyLegendInteger]) – The width of each bucket expressed in duration_unit.

  • duration_unit (str) – One of 'YEARS', 'MONTHS', 'WEEKS', 'DAYS' (case-insensitive).

Returns:

The bucket-start date.

Return type:

PyLegendDate

Raises:
  • TypeError – If quantity is not an int or PyLegendInteger.

  • ValueError – If duration_unit is not one of the supported units.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["bucket"] = frame["Shipped Date"].date_part().time_bucket(3, "MONTHS")
frame[["Shipped Date", "bucket"]].head(3).to_pandas()
Shipped Date bucket
0 1996-07-16 1996-07-01
1 1996-07-10 1996-07-01
2 1996-07-12 1996-07-01

timedelta

PyLegendDate.timedelta(number, duration_unit)[source]

Shift the date by a given amount.

Parameters:
  • number (Union[int, PyLegendInteger]) – How many units to shift (negative values shift backwards).

  • duration_unit (str) – One of 'YEARS', 'MONTHS', 'WEEKS', 'DAYS', 'HOURS', 'MINUTES', 'SECONDS', 'MILLISECONDS', 'MICROSECONDS', 'NANOSECONDS' (case-insensitive).

Returns:

The shifted date.

Return type:

PyLegendDate

Raises:
  • TypeError – If number is not an int or PyLegendInteger.

  • ValueError – If duration_unit is not a recognised unit.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["plus_7d"] = frame["Shipped Date"].timedelta(7, "DAYS")
frame[["Shipped Date", "plus_7d"]].head(3).to_pandas()
Shipped Date plus_7d
0 1996-07-16 1996-07-23
1 1996-07-10 1996-07-17
2 1996-07-12 1996-07-19

to_string

PyLegendPrimitive.to_string()[source]

Convert the value to its string representation.

Returns a string expression produced by applying the database’s CAST(... AS TEXT) (SQL) or ->toString() (Pure).

Returns:

The stringified expression.

Return type:

PyLegendString

See also

toString

Alias for to_string.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Convert an integer column to a string
frame["order_str"] = frame["Order Id"].to_string()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name order_str
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 10248
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 10249
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 10250

toString

PyLegendPrimitive.toString()[source]

Convert the value to its string representation.

Alias for to_string().

Returns:

The stringified expression.

Return type:

PyLegendString

See also

to_string

Canonical string-conversion method.

week_of_year

PyLegendDate.week_of_year()[source]

Extract the ISO week number (1–53).

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["wk"] = frame["Shipped Date"].week_of_year()
frame[["Shipped Date", "wk"]].head(3).to_pandas()
Shipped Date wk
0 1996-07-16 29
1 1996-07-10 28
2 1996-07-12 28

weekOfYear

PyLegendDate.weekOfYear()[source]

Alias for week_of_year().

Return type:

PyLegendInteger

year

PyLegendDate.year()[source]

Extract the year.

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["yr"] = frame["Shipped Date"].year()
frame[["Shipped Date", "yr"]].head(3).to_pandas()
Shipped Date yr
0 1996-07-16 1996
1 1996-07-10 1996
2 1996-07-12 1996