Skip to content

Commit 019b2bc

Browse files
author
FelixAbrahamsson
committed
Make from_subscritable work with lazy subscriptables
1 parent f61db62 commit 019b2bc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

datastream/dataset.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,17 @@ def __init__(
6565
def from_subscriptable(subscriptable) -> Dataset:
6666
'''
6767
Create ``Dataset`` based on subscriptable i.e. implements
68-
``__get_item__``. Should only be used for simple examples as a
69-
``Dataset`` created with this method does not support methods that
70-
require a source dataframe (i.e. :func:`Dataset.split` and
71-
:func:`Dataset.subset`)
68+
``__getitem__`` and ``__len__``. Should only be used for simple
69+
examples as a ``Dataset`` created with this method does not support
70+
methods that require a source dataframe (i.e. :func:``Dataset.split``
71+
and :func:``Dataset.subset``)
7272
'''
73+
7374
return (
7475
Dataset.from_dataframe(
75-
pd.DataFrame(dict(
76-
example=subscriptable
77-
))
76+
pd.DataFrame(dict(index=range(len(subscriptable))))
7877
)
79-
.map(lambda row: row['example'])
78+
.map(lambda row: subscriptable[row['index']])
8079
)
8180

8281
@staticmethod

0 commit comments

Comments
 (0)