Fix library agnosticism in random locations#679
Conversation
|
Actually, can I get another set of eyes on this issue? The scope all of the sudden seems massive. I thought it was contained to a few accidental instance checks on single dispatch methods, but it appears to be instance checking a TON of functions. If I'm scoping this correctly, I think there are 3 options:
I'm currently unaware of a way to do an instance check on a class you do not have available in your process. Happy to help out w/any of these, I would be aided by this being solved. I'd be even happier if you were to tell me I'm wrong and the problem is far more contained :) |
|
Hey, thanks for taking a look at this, and raising the original issue. If you have the chance, do you mind taking a look at this explanation, and letting me know if it does what you need? The tl;dr is that you should be able to pass a polars series to the val functions, but we should better document this 😅 edit: in case it's useful, the approach we're using in Great Tables comes from https://github.com/machow/databackend, which has some explanation around how we're able to use singledispatch without requiring pandas/polars imports |
|
@tylerriccio33, You might find our Bring Your Own DataFrame blog post helpful—feel free to check it out. |
|
I'm not the expert in how single dispatch decorator works in python, but it appears to be running an instance check when to_frame is called, which I don't think is intended. Even when i add code to convert the the list to a polars series, then pass it to to_frame, it does an instance check and fails since pandas isn't available. I feel I may be not understanding a key concept here, and therefore can't fix this. I'd really like to fix this bug, I'm running into some compatibility issues at work; it's sometimes difficult to load prod containers w/pandas due to other compatibility concerns (arrow/numpy). Let me know if i'm understanding this correctly. Pushed a new pr to show the test I'm using, which may also be the problem? |
a7a5f23 to
42cc93a
Compare
|
I came across a PyCon 2025 talk on YouTube that briefly yet clearly outlines four different ways to choose actions based on instance types. |
|
The error is happening before the function code is called, it's happening during the evaluation process in singledispatch. In |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #679 +/- ##
==========================================
- Coverage 91.18% 91.05% -0.13%
==========================================
Files 47 47
Lines 5465 5480 +15
==========================================
+ Hits 4983 4990 +7
- Misses 482 490 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This pr is imperfect but working. I found it wasn't working because Polar's
I then added additional logic to allow for a class name not defined at the top level: `class AbstractBackend(metaclass=_AbstractBackendMeta): And the new load_class function which is the workhorse: Again, not the most elegant but it appears to be effective. I've struggled to wrap my head around some aspects of how the backend works, so it's possible I'm missing finer points. Also, strictly for development purposes, I redefined some dev deps in the pyproject.toml file for uv to find, and added uv.lock to the gitignore. Feel free to reject that, just helped me code faster! |
|
I've added a test in a PR to confirm that pandas does not get imported when the vals functions run. More context in the original issue. Do you mind taking a look, and letting me know if more tests / other testing behaviors would be useful? |
|
I'm going to close (see comment in #691) -- but happy to tee up anything useful in an issue |
This is meant to fix #675 in GT and posit-dev/pointblank#132 in pointblank.
I'm brute forcing it since I see no other way. I'm replacing the single dispatch paradigm (in effected places) with an attempt to import the library in question.
FYI I'm 99% sure this would be solved by Narwhals if you wanted to go that route down the line.