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 fix: TypeError: DataFrame.sort() got an unexpected keyword argument 'reverse' #229

Merged
merged 1 commit into from
May 1, 2023

Conversation

maciejkos
Copy link
Contributor

@maciejkos maciejkos commented Apr 28, 2023

Hi!

I was test driving tidypolars today (looks great!), but I had some trouble using arrange.

import tidypolars as tp
from tidypolars import col, desc
print(tp.__version__)

tp.Tibble(x = range(3), y = range(3, 6), z = ['a', 'a', 'b']).arrange('x', 'y')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 5
      2 from tidypolars import col, desc
      3 print(tp.__version__)
----> 5 tp.Tibble(x = range(3), y = range(3, 6), z = ['a', 'a', 'b']).arrange('x', 'y')

File [c:\[snip]\anaconda3\envs\[snip]\lib\site-packages\tidypolars\tibble.py:102](file:///C:/Users/[snip]/anaconda3/envs/[snip]/lib/site-packages/tidypolars/tibble.py:102), in Tibble.arrange(self, *args)
    100 exprs = _as_list(args)
    101 desc = [True if isinstance(expr, DescCol) else False for expr in exprs]
--> 102 return super().sort(exprs, reverse = desc).pipe(from_polars)

TypeError: DataFrame.sort() got an unexpected keyword argument 'reverse'

I checked polars docs, which state that sort accepts:

Parameters:
by
Column(s) to sort by. Accepts expression input. Strings are parsed as column names.

*more_by
Additional columns to sort by, specified as positional arguments.

descending
Sort in descending order. When sorting by multiple columns, can be specified per column by passing a sequence of booleans.

nulls_last
Place null values last.

For this reason, I renamed the argument from reverse to descending, and it seems to work. I haven't run any tests.
I hope this helps, and sorry for a drive-by commit/PR.
— Maciej

Update: env info yml file attached as environment_yml.txt

Fixes:

```python
Cell In[2], line 5
      2 from tidypolars import col, desc
      3 print(tp.__version__)
----> 5 tp.Tibble(x = range(3), y = range(3, 6), z = ['a', 'a', 'b']).arrange('x', 'y')

File [c:\[snip]\anaconda3\envs\[snip]\lib\site-packages\tidypolars\tibble.py:102](file:///C:/Users/[snip]/anaconda3/envs/[snip]/lib/site-packages/tidypolars/tibble.py:102), in Tibble.arrange(self, *args)
    100 exprs = _as_list(args)
    101 desc = [True if isinstance(expr, DescCol) else False for expr in exprs]
--> 102 return super().sort(exprs, reverse = desc).pipe(from_polars)

TypeError: DataFrame.sort() got an unexpected keyword argument 'reverse'
```
@maciejkos maciejkos changed the title TypeError: DataFrame.sort() got an unexpected keyword argument 'reverse' Bug fix: TypeError: DataFrame.sort() got an unexpected keyword argument 'reverse' Apr 29, 2023
@markfairbanks
Copy link
Owner

markfairbanks commented May 1, 2023

Thanks for the fix!

polars has been implementing changes (and breaking changes) faster than I can keep up with. Changing reverse to descending in .sort() was one of them. It's good that polars is constantly improving, but the API instability makes it a bit hard to build a package that depends on it unfortunately.

There are probably a lot more fixes necessary to get tidypolars back to a good state. I'll try to get to them at some point, but between a newborn and a new job I'm bit behind on keeping this package up to date. I've only had enough time lately to keep updates to R's tidytable and dtplyr.

@markfairbanks markfairbanks merged commit 8f9b1ba into markfairbanks:main May 1, 2023
0 of 4 checks passed
@maciejkos
Copy link
Contributor Author

Thanks for the fix!
between a newborn and a new job I'm bit behind on keeping this package up to date

Don't worry about it, and thank you for maintaining so many useful packages! Also, congratulations on the new addition to your family!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants