markfairbanks / tidypolars

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

Missing attributes when chaining #204

Closed grantmcdermott closed 2 years ago

grantmcdermott commented 2 years ago

Hi Mark, thanks for putting this package together. It looks very cool.

I'm having a tough time getting the motivating examples to work, though. For example, the following triggers an error:

import tidypolars as tp
from tidypolars import col, desc

df = tp.Tibble(x = range(3), y = range(3, 6), z = ['a', 'a', 'b'])

df.filter(col('x') < 2).arrange(desc('z'), 'x')

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Untitled-1 in <cell line: 1>()
----> <a href='untitled:Untitled-1?line=7'>8</a> df.filter(col('x') < 2).arrange(desc('z'), 'x')

AttributeError: 'DataFrame' object has no attribute 'arrange'

What's genuinely odd about the above is that arrange works on its own and when it comes before filter.

# All of these work as expected
df.filter(col('x') < 2)
df.arrange(desc('z'), 'x')
df.arrange(desc('z'), 'x').filter(col('x') < 2)

A seemingly related issue is that I can't pass two arguments to filter when it follows arrange (or other verbs likeselect for that matter).

df.filter(col('x') < 2, col('y')>3) ## works
df.arrange(desc('z'), 'x').filter(col('x') < 2, col('y')>3) ## errors with "filter() takes 2 positional arguments but 3 were given"

Any ideas?

I'm on Python 3.9.2 installed via Homebrew on a 2019 Macbook (so regular Intel chip) and running the latest version of tidypolars (0.2.15).

markfairbanks commented 2 years ago

Thanks for catching this. Looks like polars made a change in v0.14.0 that broke tidypolars. I'll take a look and see if I can get it fixed sometime in the next couple days. In the meantime if you install a polars version >=0.13.44 and <0.14.0 everything should work fine.

This is one place where CRAN spoils R users. There is careful consideration for reverse dependencies so situations like this are exceedingly rare.

markfairbanks commented 2 years ago

PR that caused the break: https://github.com/pola-rs/polars/pull/4309

Old behavior that tidypolars relied on: https://github.com/pola-rs/polars/pull/2862

grantmcdermott commented 2 years ago

Super, thanks for confirming and bisecting the error.

And a big amen for stable APIs ;-)

markfairbanks commented 2 years ago

@grantmcdermott you should be good to go now for tidypolars. I just sent a release to PyPi that requires polars <0.14.0. Thanks again for catching this.

I'm also planning on adding support for >=0.14.0. Here's the issue if you want to track there: https://github.com/markfairbanks/tidypolars/issues/207

grantmcdermott commented 2 years ago

Great, thanks Mark.