-
Notifications
You must be signed in to change notification settings - Fork 541
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: names_sort argument in table.pivot_wider has no effect #9203
Labels
bug
Incorrect behavior inside of ibis
Comments
contang0
changed the title
bug: table.pivot_wider argument names_sort has no effect
bug: names_sort argument in table.pivot_wider has no effect
May 16, 2024
Hey @contang0 -- it has an effect, but the names column you've given it is already sorted (taking into account that we only need a set of column names. [ins] In [1]: import ibis
...: import pandas as pd
...:
...: ibis.options.interactive = True
...:
...: con = ibis.duckdb.connect(":memory:")
...:
...: data = pd.DataFrame(
...: {
...: "unique_id": ["A", "A", "B", "B"],
...: "secondary_id": [
...: "T2",
...: "T2",
...: "T1",
...: "T1",
...: ],
...: "col1": ["x1", "x2", "x3", "x4"],
...: "col2": ["y1", "y2", "y3", "y4"],
...: }
...: )
...:
...: tbl = ibis.memtable(data)
[ins] In [2]: tbl.pivot_wider(
...: id_cols=["unique_id"],
...: names_from=["secondary_id"],
...: values_from=["col1", "col2"],
...: names_sort=False,
...: )
Out[2]:
┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
┃ unique_id ┃ col1_T2 ┃ col2_T2 ┃ col1_T1 ┃ col2_T1 ┃
┡━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
│ string │ string │ string │ string │ string │
├───────────┼─────────┼─────────┼─────────┼─────────┤
│ A │ x1 │ y1 │ NULL │ NULL │
│ B │ NULL │ NULL │ x3 │ y3 │
└───────────┴─────────┴─────────┴─────────┴─────────┘
[ins] In [3]: tbl.pivot_wider(
...: id_cols=["unique_id"],
...: names_from=["secondary_id"],
...: values_from=["col1", "col2"],
...: names_sort=True,
...: )
Out[3]:
┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
┃ unique_id ┃ col1_T1 ┃ col2_T1 ┃ col1_T2 ┃ col2_T2 ┃
┡━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
│ string │ string │ string │ string │ string │
├───────────┼─────────┼─────────┼─────────┼─────────┤
│ A │ NULL │ NULL │ x1 │ y1 │
│ B │ x3 │ y3 │ NULL │ NULL │
└───────────┴─────────┴─────────┴─────────┴─────────┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
I'm using Table.pivot_wider to unstack rows into columns. pivot_wider has an argument names_sort, which is False by default. However, setting it True doesn't seem to have any effect.
Here's an example to reproduce and the outputs. I expected the following sorting order after setting names_sort=True:
col1_T1, col1_T2, col2_T1, col2_T2.
`
What version of ibis are you using?
9.0
What backend(s) are you using, if any?
duckdb
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: