<commit_before>from __future__ import absolute_import, division, print_function
from functools import partial

from .compatibility import _strtypes
from .compute.spark import *
from .data.utils import coerce
from .dispatch import dispatch
from .expr import Expr, TableExpr
from datashape import discover, var
from collections import Iterator, Iterable

__all__ = ['pyspark', 'coerce']

@dispatch(_strtypes, RDD)
def coerce(dshape, rdd):
    return rdd.mapPartitions(partial(coerce, dshape))


@dispatch(type, RDD)
def into(a, rdd, **kwargs):
    f = into.dispatch(a, type(rdd))
    return f(a, rdd, **kwargs)

@dispatch(object, RDD)
def into(o, rdd):
    return into(o, rdd.collect())


@dispatch((tuple, list, set), RDD)
def into(a, b, **kwargs):
    if not isinstance(a, type):
        a = type(a)
    b = b.collect()
    if isinstance(b[0], Iterable) and not type(b) == tuple:
        b = map(tuple, b)
    return a(b)


@dispatch(SparkContext, (Expr, TableExpr, RDD, object))
def into(sc, o, **kwargs):
    return sc.parallelize(into(list, o, **kwargs))

<commit_msg>spark: post_compute plays nicely with non-tuple iterables<commit_after>from __future__ import absolute_import, division, print_function
from functools import partial

from .compatibility import _strtypes
from .compute.spark import *
from .data.utils import coerce
from .dispatch import dispatch
from .expr import Expr, TableExpr
from datashape import discover, var
from collections import Iterator, Iterable

__all__ = ['pyspark', 'coerce']

@dispatch(_strtypes, RDD)
def coerce(dshape, rdd):
    return rdd.mapPartitions(partial(coerce, dshape))


@dispatch(type, RDD)
def into(a, rdd, **kwargs):
    f = into.dispatch(a, type(rdd))
    return f(a, rdd, **kwargs)

@dispatch(object, RDD)
def into(o, rdd):
    return into(o, rdd.collect())


@dispatch((tuple, list, set), RDD)
def into(a, b, **kwargs):
    if not isinstance(a, type):
        a = type(a)
    b = b.collect()
    if isinstance(b[0], (tuple, list)) and not type(b[0]) == tuple:
        b = map(tuple, b)
    return a(b)


@dispatch(SparkContext, (Expr, TableExpr, RDD, object))
def into(sc, o, **kwargs):
    return sc.parallelize(into(list, o, **kwargs))


{'fraction_non_alphanumeric': 0.13354603463992706, 'fraction_numerical': 0.0013673655423883319, 'mean_word_length': 4.501253132832081, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5849883', 'n_tokens_mistral': 764, 'n_tokens_neox': 745, 'n_words': 233}