-
Notifications
You must be signed in to change notification settings - Fork 600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: Column and Table comparison yields boolean output #10136
Comments
/take |
Thank you for reporting this bug @tokoko, and for the start of a repro! I am going to investigate how the ibis over-ride escapes this. @cpcloud What would be the expected behaviour? Would it be to error? I put together a thorough repro: import ibis
import pyarrow as pa
orders_data = pa.Table.from_pydict({
"order_id": [1,2,3,4],
"fk_store_id": [1,2,1,3],
"amount": [100,200,150,300]
})
stores_data = pa.Table.from_pydict({
"store_id": [1,2,3],
"name": ["Store A", "Store B", "Store C"]
})
con = ibis.connect("duckdb://")
orders = con.create_table("orders", orders_data)
stores = con.create_table("stores", stores_data)
print("\nCase 1: Direct comparison")
expr = orders.select(
orders["fk_store_id"],
comparison_result=(orders["fk_store_id"] == stores.select("store_id").limit(1))
)
print("\nSQL generated:")
print(ibis.to_sql(expr))
print("\nResult:")
print(expr.execute())
print("\nCase 2: Correct usage with as_scalar()")
expr_correct = orders.select(
orders["fk_store_id"],
comparison_result=(orders["fk_store_id"] == stores.select("store_id").limit(1).as_scalar())
)
print("\nSQL generated:")
print(ibis.to_sql(expr_correct))
print("\nResult:")
print(expr_correct.execute())
# Case 3: What happens with different comparison types?
print("\nCase 3: Different comparison types")
# Column to literal
print("Column to literal:", type(orders["fk_store_id"] == 1))
# Column to Column
print("Column to Column:", type(orders["fk_store_id"] == orders["order_id"]))
# Column to Table
print("Column to Table:", type(orders["fk_store_id"] == stores.select("store_id").limit(1)))
# Column to Scalar
print("Column to Scalar:", type(orders["fk_store_id"] == stores.select("store_id").limit(1).as_scalar())) This is the output:
It seems only Columns compared with Tables is returning the boolean. |
It seems that in
|
My interpreation is that Ibis tried to create an Equals operation. The Equals operation required both operands to be Value types. It can't automatically coerce a Table to a Value. So Python's Edit Probably because of:
And by default when there's a |
@cpcloud Should we be raising |
I think for some cases |
What happened?
Comparing Table and Column objects escapes ibis operator overrides and instead yields a boolean output. This is not necessarily wrong, but can lead to confusing errors when user is trying to use another table in a scalar subquery, but forgets to call
.as_scalar
method on the table. Instead of throwing an error, such a comparison will always be interpreted as a boolean literalfalse
.What version of ibis are you using?
9.5.0
What backend(s) are you using, if any?
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: