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

pl.LazyDataFrame.slice has a buggy behaviour with non scalar columns. #18304

Closed
2 tasks done
Wirg opened this issue Aug 21, 2024 · 1 comment · Fixed by #18325
Closed
2 tasks done

pl.LazyDataFrame.slice has a buggy behaviour with non scalar columns. #18304

Wirg opened this issue Aug 21, 2024 · 1 comment · Fixed by #18325
Assignees
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@Wirg
Copy link

Wirg commented Aug 21, 2024

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

import polars as pl
import tempfile
df = pl.DataFrame(
    {
        "list_struct": [[{"value": i} for _ in range(2)] for i in range(50)],
        "list": [[i for _ in range(2)] for i in range(50)],
        "struct": [{"value": i}for i in range(50)],
        "int": [i for i in range(50)],
        "str": [str(i) for i in range(50)]
     }
)
file = tempfile.mktemp(".parquet")
df.write_parquet(file)
print(pl.scan_parquet(file).collect().slice(10, 2)) # Works properly and return 10 -> 12
print(pl.scan_parquet(file).select(pl.all().slice(10, 2)).collect())  # Works properly and return 10 -> 12
# Error
print(pl.scan_parquet(file).slice(10, 2).collect())  # Works properly and return 10 -> 12 for the int and string but not for list & struct

Log output

No response

Issue description

pl.LazyDataFrame.slice returns bugged values for non scalar values by not taking offset into account.
Typically, list & struct combination will return the first element without the offset.

Input DF

list_struct list struct int str
[{0}, {0}] [0, 0] {0} 0 0
[{1}, {1}] [1, 1] {1} 1 1
[{2}, {2}] [2, 2] {2} 2 2
[{3}, {3}] [3, 3] {3} 3 3
[{4}, {4}] [4, 4] {4} 4 4
[{45}, {45}] [45, 45] {45} 45 45
[{46}, {46}] [46, 46] {46} 46 46
[{47}, {47}] [47, 47] {47} 47 47
[{48}, {48}] [48, 48] {48} 48 48
[{49}, {49}] [49, 49] {49} 49 49

✅ pl.scan_parquet(file).collect().slice(10, 2)

list_struct list struct int str
[{10}, {10}] [10, 10] {10} 10 10
[{11}, {11}] [11, 11] {11} 11 11

✅ pl.scan_parquet(file).select(pl.all().slice(10, 2)).collect()

list_struct list struct int str
[{10}, {10}] [10, 10] {10} 10 10
[{11}, {11}] [11, 11] {11} 11 11

💣 pl.scan_parquet(file).slice(10, 2).collect()

list(struct), list and struct ignores the offset but not int & str

list_struct list struct int str
[{0}, {0}] [0, 0] {0} 10 10
[{1}, {1}] [1, 1] {1} 11 11

Expected behavior

pl.LazyDataframe.slice behave similarly:

  • with scalar and struct, list columns
  • than pl.Dataframe.slice & pl.LazyDataframe.select(pl.all().slice)

Installed versions


--------Version info---------
Polars:               1.5.0
Index type:           UInt32
Platform:             macOS-14.6.1-arm64-arm-64bit
Python:               3.10.13 (main, Oct 30 2023, 14:05:33) [Clang 14.0.3 (clang-1403.0.22.14.1)]
----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          2.2.1
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               2024.5.0
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           3.9.1
nest_asyncio:         1.6.0
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.2
pyarrow:              17.0.0
pydantic:             2.8.2
pyiceberg:            <not installed>
sqlalchemy:           2.0.31
torch:                2.3.1
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@Wirg Wirg added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Aug 21, 2024
@coastalwhite
Copy link
Collaborator

Seems like we found the same bug at the same time 😄 (#18303). I am working on a fix.

@coastalwhite coastalwhite self-assigned this Aug 21, 2024
@c-peters c-peters added the accepted Ready for implementation label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants