polars.Expr.dt.is_leap_year#
- Expr.dt.is_leap_year() Expr [source]#
Determine whether the year of the underlying date is a leap year.
Applies to Date and Datetime columns.
- Returns:
- Expr
Expression of data type
Boolean
.
Examples
>>> from datetime import datetime >>> start = datetime(2000, 1, 1) >>> stop = datetime(2002, 1, 1) >>> df = pl.DataFrame( ... {"date": pl.date_range(start, stop, interval="1y", eager=True)} ... ) >>> df shape: (3, 1) ┌─────────────────────┐ │ date │ │ --- │ │ datetime[μs] │ ╞═════════════════════╡ │ 2000-01-01 00:00:00 │ │ 2001-01-01 00:00:00 │ │ 2002-01-01 00:00:00 │ └─────────────────────┘ >>> df.select(pl.col("date").dt.is_leap_year()) shape: (3, 1) ┌───────┐ │ date │ │ --- │ │ bool │ ╞═══════╡ │ true │ │ false │ │ false │ └───────┘