forked from ibis-project/ibis
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG/CLN: Fix predicates on Selections on Joins
The motivation for this PR is twofold 1) fix a bug where filters on joined data would either fail or give the wrong result, depending on which version of pandas you're on 2) refactor the `execute_selection_dataframe` function because it was getting rather large and unreadable. The bug in ibis-project#1136 was occurring due to the fact that the predicates in the `Selection` were not being evaluated against the `data` argument which is the result of the joined data. This doesn't fail on non-`Join` selections because there's no possible ambiguity regarding which column to select. The solution is to map each root table in each predicate to `data`, therefore evaluating the predicate against the joined data. Closes ibis-project#1136. Author: Phillip Cloud <cpcloud@gmail.com> Closes ibis-project#1149 from cpcloud/fix-selection-join-predicates and squashes the following commits: d76b2a8 [Phillip Cloud] BUG/CLN: Fix predicates on Selections on Joins
- Loading branch information
Showing
21 changed files
with
1,204 additions
and
593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ibis.pandas.execution.generic import * # noqa: F401,F403 | ||
from ibis.pandas.execution.selection import * # noqa: F401,F403 | ||
from ibis.pandas.execution.join import * # noqa: F401,F403 | ||
from ibis.pandas.execution.window import * # noqa: F401,F403 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Constants for the pandas backend. | ||
""" | ||
|
||
import operator | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import ibis | ||
import ibis.expr.datatypes as dt | ||
import ibis.expr.operations as ops | ||
|
||
|
||
JOIN_TYPES = { | ||
ops.LeftJoin: 'left', | ||
ops.RightJoin: 'right', | ||
ops.InnerJoin: 'inner', | ||
ops.OuterJoin: 'outer', | ||
} | ||
|
||
|
||
LEFT_JOIN_SUFFIX = '_ibis_left_{}'.format(ibis.util.guid()) | ||
RIGHT_JOIN_SUFFIX = '_ibis_right_{}'.format(ibis.util.guid()) | ||
JOIN_SUFFIXES = LEFT_JOIN_SUFFIX, RIGHT_JOIN_SUFFIX | ||
ALTERNATE_SUFFIXES = { | ||
LEFT_JOIN_SUFFIX: RIGHT_JOIN_SUFFIX, | ||
RIGHT_JOIN_SUFFIX: LEFT_JOIN_SUFFIX, | ||
} | ||
|
||
|
||
IBIS_TYPE_TO_PANDAS_TYPE = { | ||
dt.float: np.float32, | ||
dt.double: np.float64, | ||
dt.int8: np.int8, | ||
dt.int16: np.int16, | ||
dt.int32: np.int32, | ||
dt.int64: np.int64, | ||
dt.string: str, | ||
dt.timestamp: 'datetime64[ns]', | ||
} | ||
|
||
|
||
IBIS_TO_PYTHON_LITERAL_TYPES = { | ||
dt.double: float, | ||
dt.float: float, | ||
dt.int64: int, | ||
dt.int32: int, | ||
dt.int16: int, | ||
dt.int8: int, | ||
dt.string: str, | ||
dt.date: lambda x: pd.Timestamp(x).to_pydatetime().date(), | ||
} | ||
|
||
|
||
BINARY_OPERATIONS = { | ||
ops.Greater: operator.gt, | ||
ops.Less: operator.lt, | ||
ops.LessEqual: operator.le, | ||
ops.GreaterEqual: operator.ge, | ||
ops.Equals: operator.eq, | ||
ops.NotEquals: operator.ne, | ||
|
||
ops.And: operator.and_, | ||
ops.Or: operator.or_, | ||
ops.Xor: operator.xor, | ||
|
||
ops.Add: operator.add, | ||
ops.Subtract: operator.sub, | ||
ops.Multiply: operator.mul, | ||
ops.Divide: operator.truediv, | ||
ops.FloorDivide: operator.floordiv, | ||
ops.Modulus: operator.mod, | ||
ops.Power: operator.pow, | ||
} |
Oops, something went wrong.