Comments (3)
This was already discussed in #13757
This is a core issue with how selectors are currently set up as an Expr
subclass.
We have to revisit this, but doing so would be a breaking change. I have to admit that I am a bit exhausted with API design now after the release of 1.0, so I'll come back to this one a bit later.
from polars.
I believe this is covered by the following docs on selector set-ops:
https://docs.pola.rs/api/python/stable/reference/selectors.html#set-operations
However, it might not be a bad idea simply to raise an error here; allowing only selectors to interop with other selectors via operators would prevent any such ambiguity 🤔 @stinodego, how do you feel about making this a touch stricter?
from polars.
@alexander-beedie maybe I'm blind, can you quote the specific part ? This doc explains what happens with cs.by_name(), but the main issue here is the different behavior of pl.col() and cs.by_name() wrt to | and what happens when mixed together.
I can understand how they are both the correct behavior in their category how both behaviors are desirable, but the end result feel like an unfortunate API conflict:
- | overload for Expr is commutative
- | overload for selectors is commutative
- Actually they are not since the 2 kind of objects are allowed to mix together
- If the path "a selector is an expression that can be used in some specialized contexts on top of normal expr use" is taken, then Liskov substitution should apply, but it does not because of the different overload.
Taking inspiration elsewhere, if it was in Haskell they would simply be 2 different operators, since they have 2 different meaning fundamentally and there would be no problem. Cases where multiple implementations are reasonable based on use case are dealt with by not implementing it on the base types and coming up with zero-cost wrappers that "decide" which way to go (e.g. Sum and Product wrappers for Monoid). That's not really possible here since it would make Expr cumbersome to use.
Alternatively, not allowing selectors and expr to mix would fix that (and still allow some explicit mixing with selectors .to_expr()). Then everything is commutative again with no surprise, everything is still possible, and forbidden combos just raise rather than do something unexpected.
From a doc point of view, it might be interesting to stress the fact that operator overload is different than for expressions and show an example to point it out.
from polars.
Related Issues (20)
- Multiple expr.head(n).max()/min()/etc operations in with_columns causing ShapeError
- Add `repeat` and `tile` for Series/Expr
- `SchemaFieldNotFoundError` when chaining `select` and `collect`
- Series is ignoring the dtype argument, series.to_numpy() dtype depends on values passed
- Problem filtering categorical string columns with lazy frame and scan_parquet HOT 3
- PanicException: validity must be equal to the array's length
- Polars-lts-cpu fails to import on older CPU (no SSSE3/SSE4 support)
- Release GIL on `collect_schema`
- Error when using struct expression with`with_fields` in an `over` context HOT 4
- How to write a UDF for polars that run concurrently?
- `write_excel`: write column formats for column, not individual cells within column HOT 1
- Horizontal concat execution time is quadratic in the number of columns
- Incorrect results from `Series.__rtruediv__` HOT 1
- Add SQL feature of ORDER BY RAND()
- Expressions support in insert_column (like with_columns)
- "literal expressions are not allowed for sorting" error when passing polars.Series to DataFrame.sort HOT 2
- polars' ingestion of decimal.Decimal values fails if all values do not have the same number of decimal places
- Series.is_in called with a mixed list of Python integers and floats fails
- Where is indexing `__getitem__` (e.g. `df[...]`) documented for polars DataFrame and Series?
- Casting floats to strings rounds the value down.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polars.