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

fix: DataFrame.rows_by_key returning key tuples with elements in wrong order #19486

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lukemanley
Copy link
Contributor

Fixes the following and simplifies the implementation a bit.

In [1]: import polars as pl

In [2]: df = pl.DataFrame(
   ...:     {
   ...:         "w": ["a", "b", "b", "a"],
   ...:         "x": ["q", "q", "q", "k"],
   ...:         "y": [1.0, 2.5, 3.0, 4.5],
   ...:         "z": [9, 8, 7, 6],
   ...:     }
   ...: )

In [3]: df.rows_by_key(["x", "w"])
Out[3]: 
defaultdict(list,
            {('a', 'q'): [(1.0, 9)],   # <-- the key tuples are ordered as (column w, column x), not (x, w) as requested
             ('b', 'q'): [(2.5, 8), (3.0, 7)],
             ('a', 'k'): [(4.5, 6)]})

In [4]: df.rows_by_key(["x", "w"], named=True)
Out[4]: 
defaultdict(list,
            {('q', 'a'): [{'y': 1.0, 'z': 9}],   # <-- the key tuples are ordered correctly as (x, w)
             ('q', 'b'): [{'y': 2.5, 'z': 8}, {'y': 3.0, 'z': 7}],
             ('k', 'a'): [{'y': 4.5, 'z': 6}]})

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Oct 27, 2024
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.99%. Comparing base (e7a84bc) to head (8aaff53).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19486      +/-   ##
==========================================
+ Coverage   79.94%   79.99%   +0.05%     
==========================================
  Files        1534     1536       +2     
  Lines      211183   211240      +57     
  Branches     2444     2435       -9     
==========================================
+ Hits       168831   168990     +159     
+ Misses      41797    41696     -101     
+ Partials      555      554       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexander-beedie
Copy link
Collaborator

Thanks; I'll take a look at this one later tonight (or tomorrow).
Looks much simplified indeed 👍

@alexander-beedie alexander-beedie self-assigned this Oct 28, 2024
@lukemanley
Copy link
Contributor Author

@alexander-beedie - sorry for the ping, just checking in on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants