Skip to content

Commit

Permalink
additional timezone selector example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jul 1, 2023
1 parent 71792bc commit 8a4b8f8
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions py-polars/polars/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ def datetime(
>>> import polars.selectors as cs
>>> df = pl.DataFrame(
... {
... "tstamp_tokyo": [
... datetime(1999, 7, 20, 20, 20, 16, 987654),
... datetime(2000, 5, 15, 21, 21, 21, 123465),
... ],
... "tstamp_utc": [
... datetime(2023, 4, 10, 12, 14, 16, 999666),
... datetime(2025, 8, 25, 14, 18, 22, 666333),
Expand All @@ -513,6 +517,7 @@ def datetime(
... "dt": [date(1999, 12, 31), date(2010, 7, 5)],
... },
... schema_overrides={
... "tstamp_tokyo": pl.Datetime("us", "Asia/Tokyo"),
... "tstamp_utc": pl.Datetime("ns", "UTC"),
... "tstamp": pl.Datetime("ns"),
... },
Expand All @@ -521,15 +526,15 @@ def datetime(
Select all datetime columns:
>>> df.select(cs.datetime())
shape: (2, 3)
┌────────────────────────────────┬─────────────────────────┬────────────────────────────┐
│ tstamp_utc ┆ tstamp ┆ dtime │
│ --- ┆ --- ┆ --- │
│ datetime[ns, UTC] ┆ datetime[ns] ┆ datetime[μs] │
╞════════════════════════════════╪═════════════════════════╪════════════════════════════╡
│ 2023-04-10 12:14:16.999666 UTC ┆ 2000-11-20 18:12:16.600 ┆ 2010-10-10 10:25:30.987 │
│ 2025-08-25 14:18:22.666333 UTC ┆ 2020-10-30 10:20:25.123 ┆ 2024-12-31 20:30:45.400500 │
└────────────────────────────────┴─────────────────────────┴────────────────────────────┘
shape: (2, 4)
┌────────────────────────────────┬────────────────────────────────┬─────────────────────────┬────────────────────────────┐
tstamp_tokyo ┆ tstamp_utc ┆ tstamp ┆ dtime │
│ --- ┆ --- ┆ --- ┆ --- │
│ datetime[μs, Asia/Tokyo] ┆ datetime[ns, UTC] ┆ datetime[ns] ┆ datetime[μs] │
╞════════════════════════════════╪════════════════════════════════╪═════════════════════════╪════════════════════════════╡
1999-07-21 05:20:16.987654 JST ┆ 2023-04-10 12:14:16.999666 UTC ┆ 2000-11-20 18:12:16.600 ┆ 2010-10-10 10:25:30.987 │
2000-05-16 06:21:21.123465 JST ┆ 2025-08-25 14:18:22.666333 UTC ┆ 2020-10-30 10:20:25.123 ┆ 2024-12-31 20:30:45.400500 │
└────────────────────────────────┴────────────────────────────────┴─────────────────────────┴────────────────────────────┘
Select all datetime columns that have 'ns' precision:
Expand All @@ -547,15 +552,15 @@ def datetime(
Select all datetime columns that have *any* timezone:
>>> df.select(cs.datetime(time_zone="*"))
shape: (2, 1)
┌────────────────────────────────┐
│ tstamp_utc │
│ --- │
│ datetime[ns, UTC] │
╞════════════════════════════════╡
│ 2023-04-10 12:14:16.999666 UTC │
│ 2025-08-25 14:18:22.666333 UTC │
└────────────────────────────────┘
shape: (2, 2)
┌────────────────────────────────┬────────────────────────────────
tstamp_tokyo ┆ tstamp_utc │
│ --- ┆ ---
│ datetime[μs, Asia/Tokyo] ┆ datetime[ns, UTC] │
╞════════════════════════════════╪════════════════════════════════
1999-07-21 05:20:16.987654 JST ┆ 2023-04-10 12:14:16.999666 UTC │
2000-05-16 06:21:21.123465 JST ┆ 2025-08-25 14:18:22.666333 UTC │
└────────────────────────────────┴────────────────────────────────
Select all datetime columns that have a *specific* timezone:
Expand All @@ -570,7 +575,7 @@ def datetime(
│ 2025-08-25 14:18:22.666333 UTC │
└────────────────────────────────┘
Select all datetime columns that do NOT have a timezone:
Select all datetime columns that have NO timezone:
>>> df.select(cs.datetime(time_zone=None))
shape: (2, 2)
Expand Down

0 comments on commit 8a4b8f8

Please sign in to comment.