Repository: ibis-project/ibis

Issue:
bug: filter() followed by drop() fails with Csv backends
This line fails with Csv backend:

https://github.com/ibis-project/ibis/pull/1967/files#diff-365b389d018694086c2001fa6cfe0d4fR39

Stacktrace:

```
ibis/tests/all/test_join.py:44: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
ibis/expr/types.py:202: in execute
    return execute(self, limit=limit, params=params, **kwargs)
ibis/client.py:285: in execute
    return backend.execute(expr, limit=limit, params=params, **kwargs)
ibis/file/client.py:38: in execute
    return execute_and_reset(expr, params=params, **kwargs)
ibis/pandas/core.py:414: in execute_and_reset
    expr, params=params, scope=scope, aggcontext=aggcontext, **kwargs
../../miniconda3/envs/ibis-dev/lib/python3.7/site-packages/multipledispatch/dispatcher.py:278: in __call__
    return func(*args, **kwargs)
ibis/pandas/core.py:371: in main_execute
    return execute_with_scope(expr, new_scope, aggcontext=aggcontext, **kwargs)
ibis/pandas/core.py:190: in execute_with_scope
    **kwargs,
ibis/pandas/core.py:226: in execute_until_in_scope
    **kwargs,
ibis/pandas/core.py:294: in execute_bottom_up
    for arg in computable_args
ibis/pandas/core.py:294: in <listcomp>
    for arg in computable_args
ibis/pandas/core.py:319: in execute_bottom_up
    **kwargs,
../../miniconda3/envs/ibis-dev/lib/python3.7/site-packages/multipledispatch/dispatcher.py:278: in __call__
    return func(*args, **kwargs)
ibis/pandas/execution/selection.py:309: in execute_selection_dataframe
    predicate = functools.reduce(operator.and_, predicates)
ibis/pandas/execution/selection.py:233: in _compute_predicates
    yield execute(predicate, scope=new_scope, **kwargs)
../../miniconda3/envs/ibis-dev/lib/python3.7/site-packages/multipledispatch/dispatcher.py:278: in __call__
    return func(*args, **kwargs)
ibis/pandas/core.py:371: in main_execute
    return execute_with_scope(expr, new_scope, aggcontext=aggcontext, **kwargs)
ibis/pandas/core.py:190: in execute_with_scope
    **kwargs,
ibis/pandas/core.py:226: in execute_until_in_scope
    **kwargs,
ibis/pandas/core.py:294: in execute_bottom_up
    for arg in computable_args
ibis/pandas/core.py:294: in <listcomp>
    for arg in computable_args
ibis/pandas/core.py:319: in execute_bottom_up
    **kwargs,
../../miniconda3/envs/ibis-dev/lib/python3.7/site-packages/multipledispatch/dispatcher.py:278: in __call__
    return func(*args, **kwargs)
ibis/pandas/execution/generic.py:379: in execute_table_column_df_or_df_groupby
    return data[op.name]
../../miniconda3/envs/ibis-dev/lib/python3.7/site-packages/pandas/core/frame.py:2927: in __getitem__
    indexer = self.columns.get_loc(key)
../../miniconda3/envs/ibis-dev/lib/python3.7/site-packages/pandas/core/indexes/base.py:2659: in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
pandas/_libs/index.pyx:108: in pandas._libs.index.IndexEngine.get_loc
    ???
pandas/_libs/index.pyx:132: in pandas._libs.index.IndexEngine.get_loc
    ???
pandas/_libs/hashtable_class_helper.pxi:1601: in pandas._libs.hashtable.PyObjectHashTable.get_item
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   KeyError: 'lgID'
```


Discussion:
@icexelloss Is this still an issue?

Resolving patch:
diff --git a/ibis/backends/csv/__init__.py b/ibis/backends/csv/__init__.py
--- a/ibis/backends/csv/__init__.py
+++ b/ibis/backends/csv/__init__.py
@@ -4,10 +4,7 @@
 import ibis.expr.operations as ops
 import ibis.expr.schema as sch
 from ibis.backends.base.file import BaseFileBackend
-from ibis.backends.pandas.core import execute, execute_node, pre_execute
-from ibis.backends.pandas.execution.selection import physical_tables
-from ibis.expr.scope import Scope
-from ibis.expr.typing import TimeContext
+from ibis.backends.pandas.core import execute, execute_node
 
 
 def _read_csv(path, schema, **kwargs):
@@ -60,40 +57,6 @@ def table(self, name, path=None, schema=None, **kwargs):
         return table
 
 
-@pre_execute.register(ops.Selection, Backend)
-def csv_pre_execute_selection(
-    op: ops.Node,
-    client: Backend,
-    scope: Scope,
-    timecontext: TimeContext = None,
-    **kwargs,
-):
-    tables = filter(
-        lambda t: scope.get_value(t, timecontext) is None,
-        physical_tables(op.table.op()),
-    )
-
-    ops = Scope()
-    for table in tables:
-        path = client.dictionary[table.name]
-        usecols = None
-
-        if op.selections:
-            header = _read_csv(path, schema=table.schema, header=0, nrows=1)
-            usecols = [
-                getattr(s.op(), 'name', None) or s.get_name()
-                for s in op.selections
-            ]
-
-            # we cannot read all the columns that we would like
-            if len(pd.Index(usecols) & header.columns) != len(usecols):
-                usecols = None
-        result = _read_csv(path, table.schema, usecols=usecols, header=0)
-        ops = ops.merge_scope(Scope({table: result}, timecontext))
-
-    return ops
-
-
 @execute_node.register(Backend.table_class, Backend)
 def csv_read_table(op, client, scope, **kwargs):
     path = client.dictionary[op.name]


Test patch:
diff --git a/ibis/backends/tests/test_join.py b/ibis/backends/tests/test_join.py
--- a/ibis/backends/tests/test_join.py
+++ b/ibis/backends/tests/test_join.py
@@ -3,7 +3,7 @@
 from pytest import param
 
 # add here backends that passes join tests
-all_db_join_supported = ['pandas', 'pyspark', 'dask']
+all_db_join_supported = ['pandas', 'pyspark', 'dask', 'csv']
 
 
 @pytest.mark.parametrize(
@@ -29,7 +29,6 @@
 )
 @pytest.mark.only_on_backends(all_db_join_supported)
 # Csv is a subclass of Pandas so need to skip it explicitly.
-@pytest.mark.skip_backends(['csv'])
 @pytest.mark.xfail_unsupported
 def test_join_project_left_table(backend, con, batting, awards_players, how):