Skip to content

ISO year/week (via EXTRACT) appear to have some edge-cases #5776

@alexander-beedie

Description

@alexander-beedie

What happens?

Seems that ISO year/week are not always determined correctly, with respect to other implementations. For example, 2024-12-31 should have week => 1, isoyear => 2025, but duckdb returns week => 53, isoyear => 2024.

To Reproduce

Setup

import duckdb
import pandas as pd

df = pd.DataFrame( {'dt':[datetime(2024,12,31)]} )

DuckDB result

dconn = duckdb.connect()
dconn.execute("""
  SELECT
    EXTRACT(week FROM dt) AS week,
    EXTRACT(isoyear FROM dt) AS isoyear
  FROM df
""").fetchall()

# week    => 53
# isoyear => 2024

Pandas result

df['dt'].dt.isocalendar().week[0]  # => 1
df['dt'].dt.isocalendar().year[0]  # => 2025

Python result

date(2024,12,31).isocalendar().week  # => 1
date(2024,12,31).isocalendar().year  # => 2025

Other backend results

PostgreSQL, Redshift, TimescaleDB, Polars:

# week    => 1
# isoyear => 2025

OS:

macOS 13.01

DuckDB

Python, v0.6.1

Full Name, Affiliation:

Alexander Beedie, ADIA

Have you tried this on the latest master branch?

  • I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • I agree

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions