Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: group_by_dynamic period and every get applied in reverse order #19704

Closed
2 tasks done
MarcoGorelli opened this issue Nov 8, 2024 · 0 comments · Fixed by #19706
Closed
2 tasks done

bug: group_by_dynamic period and every get applied in reverse order #19704

MarcoGorelli opened this issue Nov 8, 2024 · 0 comments · Fixed by #19706
Assignees
Labels
A-temporal Area: date/time functionality bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@MarcoGorelli
Copy link
Collaborator

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

In [18]: df = pl.DataFrame({'a': [datetime(2020, 1, 1), datetime(2020, 2, 1), datetime(2020, 3, 1)], 'b': [1,2,3]})

In [19]: df.group_by_dynamic('a', every='1mo', period='45d', include_boundaries=True).agg(pl.col('b').sum())
Out[19]:
shape: (3, 4)
┌─────────────────────┬─────────────────────┬─────────────────────┬─────┐
│ _lower_boundary_upper_boundaryab   │
│ ------------ │
│ datetime[μs]        ┆ datetime[μs]        ┆ datetime[μs]        ┆ i64 │
╞═════════════════════╪═════════════════════╪═════════════════════╪═════╡
│ 2020-01-01 00:00:002020-02-15 00:00:002020-01-01 00:00:003   │
│ 2020-02-01 00:00:002020-03-15 00:00:002020-02-01 00:00:005   │
│ 2020-03-01 00:00:002020-04-15 00:00:002020-03-01 00:00:003   │
└─────────────────────┴─────────────────────┴─────────────────────┴─────┘

Log output

No response

Issue description

It looks like period is getting applied before every, as opposed to

[start + every, start + every + period)

which is what's documented

I think the documentation expresses the desired behaviour - if you pass period=45d, then you expect each period to be 45 days long

Expected behavior

shape: (3, 4)
┌─────────────────────┬─────────────────────┬─────────────────────┬─────┐
│ _lower_boundary     ┆ _upper_boundary     ┆ a                   ┆ b   │
│ ---                 ┆ ---                 ┆ ---                 ┆ --- │
│ datetime[μs]        ┆ datetime[μs]        ┆ datetime[μs]        ┆ i64 │
╞═════════════════════╪═════════════════════╪═════════════════════╪═════╡
│ 2020-01-01 00:00:00 ┆ 2020-02-15 00:00:00 ┆ 2020-01-01 00:00:00 ┆ 3   │
│ 2020-02-01 00:00:00 ┆ 2022-03-18 00:00:00 ┆ 2020-02-01 00:00:00 ┆ 5   │
│ 2020-03-01 00:00:00 ┆ 2022-04-15 00:00:00 ┆ 2020-03-01 00:00:00 ┆ 3   │
└─────────────────────┴─────────────────────┴─────────────────────┴─────┘

Installed versions

--------Version info---------
Polars:              1.12.0
Index type:          UInt32
Platform:            Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python:              3.12.5 (main, Aug 14 2024, 05:08:31) [Clang 18.1.8 ]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               5.4.1
cloudpickle          3.0.0
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               2024.9.0
gevent               <not installed>
great_tables         0.11.0
matplotlib           3.9.2
nest_asyncio         1.6.0
numpy                2.1.3
openpyxl             <not installed>
pandas               2.2.3
pyarrow              18.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@MarcoGorelli MarcoGorelli added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer A-temporal Area: date/time functionality P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Nov 8, 2024
@MarcoGorelli MarcoGorelli self-assigned this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-temporal Area: date/time functionality bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Status: Done
1 participant