question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(backends): unexpected chained join behavior

See original GitHub issue

Chained joins in pandas backend don’t behave as expected, and yield an error.

MWE:

import ibis
import pandas as pd

test_df1 = pd.DataFrame({
    'id': ['1', '1'],
    'value': ['a', 'a']
})

test_df2 = pd.DataFrame({
    'id': ['1', '1'],
    'value': ['z', 'z']
})

test_df3 = pd.DataFrame({
    'id': ['1', '1'],
    'value': ['z1', 'z1']
})

conn = ibis.pandas.connect({'df1': test_df1,
                            'df2': test_df2,
                            'df3': test_df3})

t1 = conn.table('df1')
t2 = conn.table('df2')
t3 = conn.table('df3')

expr1 = t1.join(t2, t1.id == t2.id)
expr2 = t1.join(t2, t1.id == t2.id).join(t3, t1.id == t3.id)

#works
print('\n'+expr1.execute())

#fails
print('\n'+expr2.execute())

Error:

KeyError: PandasTable(name='df1', schema=ibis.Schema {
  id     string
  value  string
}, source=<ibis.backends.pandas.Backend object at 0x7f4edbb87e80>)

Does the pandas backend support chained joins / is there a different syntax required than the docs suggest here -> https://ibis-project.org/docs/3.1.0/ibis-for-sql-programmers/?h=left_join#multiple-joins ?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
cpcloudcommented, Nov 7, 2022

In the meantime you should be able to write

from ibis import _
result = t1.join(t2, t1.id==t2.id).join(t3, _.id==t3.id)

Note the _, it refers to everything to the left of the second join call.

0reactions
cpcloudcommented, Nov 29, 2022

Interestingly, this appears to be related to overlapping column names in some way:

Not Working

t1 = ibis.table(dict(id="int64"), name="t1")
t2 = ibis.table(dict(id="int64"), name="t2")
t3 = ibis.table(dict(id="int64"), name="t3")

expr = t1.join(t2, t1.id == t2.id).join(t3, t1.id == t3.id)
ibis.show_sql(expr, dialect="duckdb")
SELECT
  t0.id AS id_x,
  t1.id AS id_y
FROM (
  SELECT
    t2.id AS id
  FROM t1 AS t2
  JOIN t2 AS t3
    ON t2.id = t3.id
) AS t0
JOIN t3 AS t1
  ON t2.id = t1.id

Working

t1 = ibis.table(dict(id1="int64"), name="t1")
t2 = ibis.table(dict(id2="int64"), name="t2")
t3 = ibis.table(dict(id3="int64"), name="t3")

expr = t1.join(t2, t1.id1 == t2.id2).join(t3, t1.id1 == t3.id3)
ibis.show_sql(expr, dialect="duckdb")
SELECT
  t0.id1,
  t1.id2,
  t2.id3
FROM t1 AS t0
JOIN t2 AS t1
  ON t0.id1 = t1.id2
JOIN t3 AS t2
  ON t0.id1 = t2.id3
Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · ibis-project/ibis · GitHub
bug (backends): unexpected chained join behavior backends Issues related to all backends breaking change Changes that introduce an API break at any level...
Read more >
Resolvers - Apollo GraphQL Docs
A resolver is a function that's responsible for populating the data for a single field in your schema. It can populate that data...
Read more >
Bug with JOIN ... USING ... - Snowflake Community
There appears to be a bug when using. SELECT * FROM a; JOIN b USING (attribute1). Fist weird thing is that there is...
Read more >
5 Most Common useState Mistakes React Developers Often ...
In simpler terms, if any chained object is missing, it doesn't continue with the chain operation (short-circuits). For example, user?.names?.
Read more >
The 10 Most Common JavaScript Issues Developers Face
If you need help figuring out why your JavaScript isn't working, consult this list of the 10 most common JavaScript issues from a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found