Chain filtering is leaking
NONE
### Update:
I wrote a bit cleaner code snippet (without transforming to json) that can expose leaking.
```python
import datasets
import json

items = ['ab', 'c', 'df']

ds = datasets.Dataset.from_dict({'col': items})
print(list(ds))
# > Prints: [{'col': 'ab'}, {'col': 'c'}, {'col': 'df'}]

filtered = ds

# get all items that are starting with a character with ascii code bigger than 'a'
filtered = filtered.filter(lambda x: x['col'][0] > 'a', load_from_cache_file=False)
print(list(filtered))
# > Prints: [{'col': 'c'}, {'col': 'df'}] as expected

# get all items that are shorter than 2
filtered = filtered.filter(lambda x: len(x['col']) < 2, load_from_cache_file=False)
print(list(filtered))
# > Prints: [{'col': 'ab'}] -> this is a leaked item from the first filter
# > Should be: [{'col': 'c'}]
```
2021-10-04T09:25:49Z
https://github.com/huggingface/datasets/issues/3010#issuecomment-933306189
https://api.github.com/repos/huggingface/datasets/issues/3010
IC_kwDODunzps43oR9N
https://api.github.com/repos/huggingface/datasets/issues/comments/933306189/reactions
2021-10-04T09:27:04Z
https://api.github.com/repos/huggingface/datasets/issues/comments/933306189
https://avatars.githubusercontent.com/u/22641583?v=4
https://api.github.com/users/DrMatters/events{/privacy}
https://api.github.com/users/DrMatters/followers
https://api.github.com/users/DrMatters/following{/other_user}
https://api.github.com/users/DrMatters/gists{/gist_id}
https://github.com/DrMatters
DrMatters
MDQ6VXNlcjIyNjQxNTgz
https://api.github.com/users/DrMatters/orgs
https://api.github.com/users/DrMatters/received_events
https://api.github.com/users/DrMatters/repos
https://api.github.com/users/DrMatters/starred{/owner}{/repo}
https://api.github.com/users/DrMatters/subscriptions
User
https://api.github.com/users/DrMatters
public
MEMBER
Thanks for reporting. I'm looking into it
2021-10-04T14:45:52Z
https://github.com/huggingface/datasets/issues/3010#issuecomment-933558541
https://api.github.com/repos/huggingface/datasets/issues/3010
IC_kwDODunzps43pPkN
https://api.github.com/repos/huggingface/datasets/issues/comments/933558541/reactions
2021-10-04T14:45:52Z
https://api.github.com/repos/huggingface/datasets/issues/comments/933558541
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
MEMBER
I just pushed a fix ! We'll do a new release soon.
In the meantime feel free to install `datasets` from source to play with it
2021-10-05T08:34:24Z
https://github.com/huggingface/datasets/issues/3010#issuecomment-934189733
https://api.github.com/repos/huggingface/datasets/issues/3010
IC_kwDODunzps43rpql
https://api.github.com/repos/huggingface/datasets/issues/comments/934189733/reactions
2021-10-05T08:34:24Z
https://api.github.com/repos/huggingface/datasets/issues/comments/934189733
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
NONE
Thanks, I'm already using it from your branch!
2021-10-05T08:36:08Z
https://github.com/huggingface/datasets/issues/3010#issuecomment-934191106
https://api.github.com/repos/huggingface/datasets/issues/3010
IC_kwDODunzps43rqAC
https://api.github.com/repos/huggingface/datasets/issues/comments/934191106/reactions
2021-10-05T08:36:08Z
https://api.github.com/repos/huggingface/datasets/issues/comments/934191106
https://avatars.githubusercontent.com/u/22641583?v=4
https://api.github.com/users/DrMatters/events{/privacy}
https://api.github.com/users/DrMatters/followers
https://api.github.com/users/DrMatters/following{/other_user}
https://api.github.com/users/DrMatters/gists{/gist_id}
https://github.com/DrMatters
DrMatters
MDQ6VXNlcjIyNjQxNTgz
https://api.github.com/users/DrMatters/orgs
https://api.github.com/users/DrMatters/received_events
https://api.github.com/users/DrMatters/repos
https://api.github.com/users/DrMatters/starred{/owner}{/repo}
https://api.github.com/users/DrMatters/subscriptions
User
https://api.github.com/users/DrMatters
public
## Describe the bug
As there's no support for lists within dataset fields, I convert my lists to json-string format. However, the bug described is occurring even when the data format is 'string'.
These samples show that filtering behavior diverges from what's expected when chaining filterings.
On sample 2 the second filtering leads to "leaking" of data that should've been filtered on the first filtering into the results.

## Steps to reproduce the bug
Sample 1:
```python
import datasets
import json

items = [[1, 2], [3], [4]]
jsoned_items = map(json.dumps, [[1, 2], [3], [4]])
ds = datasets.Dataset.from_dict({'a': jsoned_items})
print(list(ds))
# > Prints: [{'a': '[1, 2]'}, {'a': '[3]'}, {'a': '[4]'}] as expected

filtered = ds

# get all lists that are shorter than 2
filtered = filtered.filter(lambda x: len(json.loads(x['a'])) < 2, load_from_cache_file=False)
print(list(filtered))
# > Prints: [{'a': '[3]'}, {'a': '[4]'}] as expected

# get all lists, which have a value bigger than 3 on its zero index
filtered = filtered.filter(lambda x: json.loads(x['a'])[0] > 3, load_from_cache_file=False)
print(list(filtered))
# > Should be: [{'a': [4]}]
# > Prints: [{'a': [3]}]
```
Sample 2:
```python
import datasets
import json

items = [[1, 2], [3], [4]]
jsoned_items = map(json.dumps, [[1, 2], [3], [4]])
ds = datasets.Dataset.from_dict({'a': jsoned_items})
print(list(ds))
# > Prints: [{'a': '[1, 2]'}, {'a': '[3]'}, {'a': '[4]'}]

filtered = ds

# get all lists, which have a value bigger than 3 on its zero index
filtered = filtered.filter(lambda x: json.loads(x['a'])[0] > 3, load_from_cache_file=False)
print(list(filtered))
# > Prints: [{'a': '[4]'}] as expected

# get all lists that are shorter than 2
filtered = filtered.filter(lambda x: len(json.loads(x['a'])) < 2, load_from_cache_file=False)
print(list(filtered))
# > Prints: [{'a': '[1, 2]'}]
# > Should be: [{'a': '[4]'}] (remain intact)
```

## Expected results
Expected and actual results are attached to the code snippets.

## Actual results
Expected and actual results are attached to the code snippets.

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version: 1.12.1
- Platform: Windows-10-10.0.19042-SP0
- Python version: 3.9.7
- PyArrow version: 5.0.0
