@@ -120,6 +120,17 @@ def _partition_lazy(d, key: str):
120120 return d [key ] if d .partitioned else d
121121 return d
122122
123+ def _dummy_return (a ):
124+ return a
125+
126+ def _wrap_lazy (d , cls ):
127+ if isinstance (d , tuple ):
128+ return tuple ([_wrap_lazy (v , cls ) for v in d ])
129+ if isinstance (d , list ):
130+ return [_wrap_lazy (v , cls ) for v in d ]
131+ if isinstance (d , dict ):
132+ return {k : _wrap_lazy (v , cls ) for k , v in d .items ()}
133+ return cls (partial (_dummy_return , d ))
123134
124135class LazyDataset (Generic [A ], LazyPartition [A ]):
125136 def __init__ (
@@ -282,7 +293,7 @@ def zip_values(*positional, **keyword) -> list:
282293 elif positional :
283294 return [positional ]
284295 elif keyword :
285- return [keyword ] # type: ignore
296+ return [keyword ]
286297 return [()]
287298
288299 return list (LazyDataset .zip (* positional , ** keyword ).values ())
@@ -304,6 +315,21 @@ def __len__(self):
304315 return 1
305316 return 0
306317
318+ @classmethod
319+ def wrap (cls , * positional , ** keyword ):
320+ """ Converts provided arguments to lazy. Tuples, dicts, and lists are traversed,
321+ and every object found in them is wrapped in a LazyDataset."""
322+ if positional and keyword :
323+ return _wrap_lazy ((positional , keyword ), cls )
324+ elif positional and len (positional ) == 1 :
325+ return _wrap_lazy (positional [0 ], cls )
326+ elif positional :
327+ return _wrap_lazy (positional , cls )
328+ elif keyword :
329+ return _wrap_lazy (keyword , cls )
330+ return None
331+
332+
307333
308334LazyFrame = LazyDataset ["pd.DataFrame" ]
309335
0 commit comments