<commit_before>from __future__ import absolute_import, division, print_function

import numbers
import toolz
import inspect
import functools
import datashape

from toolz import unique, concat, memoize, partial
import toolz
from pprint import pprint
from blaze.compatibility import StringIO

from .method_dispatch import select_functions
from ..dispatch import dispatch

__all__ = ['Expr', 'discover', 'path', 'ElemWise']


def get_callable_name(o):
    """Welcome to str inception. Leave your kittens at home.
    """
    # special case partial objects
    if isinstance(o, functools.partial):
        return 'partial(%s, %s)' % (get_callable_name(o.func),
                                    ', '.join(map(str, o.args)))

    try:
        # python 3 makes builtins look nice
        return o.__qualname__
    except AttributeError:
        try:
            # show the module of the object, if we can
            return '%s.%s' % (inspect.getmodule(o).__name__, o.__name__)
        except AttributeError:
            try:
                # __self__ tells us the class the method is bound to
                return '%s.%s' % (o.__self__.__name__, o.__name__)
            except AttributeError:
                # exhausted all avenues of printing callables so just print the
                # name of the object
                return o.__name__


def _str(s):
    """ Wrap single quotes around strings """
    if isinstance(s, str):
        return "'%s'" % s
    elif callable(s):
        return get_callable_name(s)
    else:
        stream = StringIO()
        pprint(s, stream=stream)
        return stream.getvalue().rstrip()


class Expr(object):
    __inputs__ = 'child',

    def __init__(self, *args, **kwargs):
        assert frozenset(kwargs).issubset(self.__slots__)

        for slot, arg in zip(self.__slots__, args):
            setattr(self, slot, arg)

        for key, value in kwargs.items():
            setattr(self, key, value)

    @property
    def args(self):
        return tuple(getattr(self, slot) for slot in self.__slots__)

    @property
    def inputs(self):
        return tuple(getattr(self, i) for i in self.__inputs__)

    @property
    def shape(self):
        s = list(self.dshape.shape)
        for i, elem in enumerate(s):
            try:
                s[i] = int(elem)
            except TypeError:
                pass

        return tuple(s)

    @property
    def schema(self):
        return datashape.dshape(self.dshape[-1])

    @property
    def names(self):
        if isinstance(self.dshape.measure, datashape.Record):
            return self.dshape.measure.names
        if hasattr(self, '_name'):
            return [self._name]
<commit_msg>move nonzero, bool to Expr<commit_after>from __future__ import absolute_import, division, print_function

import numbers
import toolz
import inspect
import functools
import datashape

from toolz import unique, concat, memoize, partial
import toolz
from pprint import pprint
from blaze.compatibility import StringIO

from .method_dispatch import select_functions
from ..dispatch import dispatch

__all__ = ['Expr', 'discover', 'path', 'ElemWise']


def get_callable_name(o):
    """Welcome to str inception. Leave your kittens at home.
    """
    # special case partial objects
    if isinstance(o, functools.partial):
        return 'partial(%s, %s)' % (get_callable_name(o.func),
                                    ', '.join(map(str, o.args)))

    try:
        # python 3 makes builtins look nice
        return o.__qualname__
    except AttributeError:
        try:
            # show the module of the object, if we can
            return '%s.%s' % (inspect.getmodule(o).__name__, o.__name__)
        except AttributeError:
            try:
                # __self__ tells us the class the method is bound to
                return '%s.%s' % (o.__self__.__name__, o.__name__)
            except AttributeError:
                # exhausted all avenues of printing callables so just print the
                # name of the object
                return o.__name__


def _str(s):
    """ Wrap single quotes around strings """
    if isinstance(s, str):
        return "'%s'" % s
    elif callable(s):
        return get_callable_name(s)
    else:
        stream = StringIO()
        pprint(s, stream=stream)
        return stream.getvalue().rstrip()


class Expr(object):
    __inputs__ = 'child',

    def __init__(self, *args, **kwargs):
        assert frozenset(kwargs).issubset(self.__slots__)

        for slot, arg in zip(self.__slots__, args):
            setattr(self, slot, arg)

        for key, value in kwargs.items():
            setattr(self, key, value)

    def __nonzero__(self): # pragma: no cover
        return True

    def __bool__(self):
        return True

    @property
    def args(self):
        return tuple(getattr(self, slot) for slot in self.__slots__)

    @property
    def inputs(self):
        return tuple(getattr(self, i) for i in self.__inputs__)

    @property
    def shape(self):
        s = list(self.dshape.shape)
        for i, elem in enumerate(s):
            try:
                s[i] = int(elem)
            except TypeError:
                pass

        return tuple(s)

    @property
    def schema(self):
        return datashape.dshape(self.dshape[-1])

    @property
    def names(self):
        if isinstance(self.dshape.measure, datashape.Record):
            return self.dshape.measure.names
        if hasattr(self, '_name'):
            return [self._name]

{'fraction_non_alphanumeric': 0.09624796084828711, 'fraction_numerical': 0.0007250317201377561, 'mean_word_length': 2.2025536854323855, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6392577', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1559, 'n_words': 489}