Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

dict_keys and dict_values types do not work with filter_by #2221 #2470

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/python/turicreate/data_structures/sarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def _is_iterable_required_to_listify(cls, obj):
# In Python 3, str implements '__iter__'.
return (isinstance(obj, types.GeneratorType) or
(sys.version_info.major < 3 and isinstance(obj, six.moves.xrange)) or
sys.version_info.major >= 3 and isinstance(obj, (range, filter, map)))
sys.version_info.major >= 3 and isinstance(obj, (range, filter, map, collections.abc.KeysView, collections.abc.ValuesView)))


def __init__(self, data=[], dtype=None, ignore_cast_failure=False, _proxy=None):
Expand Down
14 changes: 14 additions & 0 deletions src/python/turicreate/test/test_sframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3772,6 +3772,20 @@ def test_add_column_noniterable2(self):

_assert_sframe_equal(sf, sf_test)


def test_filter_by_dict(self):
# Check for dict in filter_by
sf = SFrame({'check':range(10)})
d = {1:1}

sf = sf.filter_by(d.keys(),'check')
sf_test = sf.filter_by(list(d.keys()),'check')
_assert_sframe_equal(sf, sf_test)

sf = sf.filter_by(d.values(),'check')
sf_test = sf.filter_by(list(d.values()),'check')
_assert_sframe_equal(sf, sf_test)


if __name__ == "__main__":

Expand Down