markfairbanks / tidypolars

Tidy interface to polars
http://tidypolars.readthedocs.io
MIT License
321 stars 10 forks source link

Bug fix: TypeError: DataFrame.sort() got an unexpected keyword argument 'reverse' #229

Closed maciejkos closed 1 year ago

maciejkos commented 1 year ago

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

markfairbanks commented 1 year ago

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.

maciejkos commented 1 year ago

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!