
On 2019-10-07 20:35, Steven D'Aprano wrote:
As per Caleb's initial post, this is how Pandas currently does it:
db[db['x'] == 1]
Replacing that with db[x=1] seems like a HUGE win to me.
Even db[{'x': 1}] is pretty clunky.
For Pandas, db['x'] which creates an expression involving `x`, and can be used in more than one place. It is small matter to start your method (or class, or module) with some declarations:
x = db['x']
which is boilerplate, but also easily ignored. Then you can write
db[x==1]
Which is just as clean, and more specific, than whatever `db[x=1]` means. I do not believe this syntax will help Pandas because equality is just one-of-many useful operators. This does not help me if I want to say
db[x>1]
or say
db[x==1 || t > 2]
I am not sure how many expressions are actually found in realworld code. Examples are written out, but most code is not examples. Most code, that I have seen, manipulates expressions that come from elsewhere. Here is an Elasticsearch expression:
e = {"term": {"x": 1}}
which is not seen in the code; assignment to `e` is done elsewhere, maybe from a config file, maybe from another application. The code only sees `e`. Therefore an example like
db[db['x'] == 1]
looks like
db[e]
in realworld code.