<commit_before>from __future__ import absolute_import, division, print_function

from datashape import dshape, Record
from toolz import pluck, get
from contextlib import contextmanager
import inspect
import datetime
import tempfile
import os
import numpy as np
from .compatibility import unicode


def raises(err, lamda):
    try:
        lamda()
        return False
    except err:
        return True


def expand_tuples(L):
    """

    >>> expand_tuples([1, (2, 3)])
    [(1, 2), (1, 3)]

    >>> expand_tuples([1, 2])
    [(1, 2)]
    """
    if not L:
        return [()]
    elif not isinstance(L[0], tuple):
        rest = expand_tuples(L[1:])
        return [(L[0],) + t for t in rest]
    else:
        rest = expand_tuples(L[1:])
        return [(item,) + t for t in rest for item in L[0]]

@contextmanager
def tmpfile(extension=''):
    extension = '.' + extension.lstrip('.')
    handle, filename = tempfile.mkstemp(extension)
    os.remove(filename)

    yield filename

    try:
        if os.path.exists(filename):
            os.remove(filename)
    except OSError:  # Sometimes Windows can't close files
        if os.name == 'nt':
            os.close(handle)
            try:
                os.remove(filename)
            except OSError:  # finally give up
                pass


def keywords(func):
    """ Get the argument names of a function

    >>> def f(x, y=2):
    ...     pass

    >>> keywords(f)
    ['x', 'y']
    """
    if isinstance(func, type):
        return keywords(func.__init__)
    return inspect.getargspec(func).args


def cls_name(cls):<commit_msg>close temporary file handle before deletion<commit_after>from __future__ import absolute_import, division, print_function

from datashape import dshape, Record
from toolz import pluck, get
from contextlib import contextmanager
import inspect
import datetime
import tempfile
import os
import numpy as np
from .compatibility import unicode


def raises(err, lamda):
    try:
        lamda()
        return False
    except err:
        return True


def expand_tuples(L):
    """

    >>> expand_tuples([1, (2, 3)])
    [(1, 2), (1, 3)]

    >>> expand_tuples([1, 2])
    [(1, 2)]
    """
    if not L:
        return [()]
    elif not isinstance(L[0], tuple):
        rest = expand_tuples(L[1:])
        return [(L[0],) + t for t in rest]
    else:
        rest = expand_tuples(L[1:])
        return [(item,) + t for t in rest for item in L[0]]

@contextmanager
def tmpfile(extension=''):
    extension = '.' + extension.lstrip('.')
    handle, filename = tempfile.mkstemp(extension)
    os.close(handle)
    os.remove(filename)

    yield filename

    try:
        if os.path.exists(filename):
            os.remove(filename)
    except OSError:  # Sometimes Windows can't close files
        if os.name == 'nt':
            os.close(handle)
            try:
                os.remove(filename)
            except OSError:  # finally give up
                pass


def keywords(func):
    """ Get the argument names of a function

    >>> def f(x, y=2):
    ...     pass

    >>> keywords(f)
    ['x', 'y']
    """
    if isinstance(func, type):
        return keywords(func.__init__)
    return inspect.getargspec(func).args


def cls_name(cls):
{'fraction_non_alphanumeric': 0.12241751464693185, 'fraction_numerical': 0.010484119642306507, 'mean_word_length': 2.3512396694214877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '4758035', 'n_tokens_mistral': 1043, 'n_tokens_neox': 991, 'n_words': 305}