<commit_before>from __future__ import print_function, division, absolute_import

import bz2
import zlib

from toolz import identity

from ..compatibility import gzip_compress, gzip_decompress, GzipFile, PY2
from ..utils import ignoring


def noop_file(file, **kwargs):
    return file


compress = {'gzip': gzip_compress,
            'zlib': zlib.compress,
            'bz2': bz2.compress,
            None: identity}
decompress = {'gzip': gzip_decompress,
              'zlib': zlib.decompress,
              'bz2': bz2.decompress,
              None: identity}
files = {'gzip': lambda f, **kwargs: GzipFile(fileobj=f, **kwargs),
         None: noop_file}
seekable_files = {None: noop_file}


with ignoring(ImportError):
    import snappy
    compress['snappy'] = snappy.compress
    decompress['snappy'] = snappy.decompress

<commit_msg>Also ignore AttributeErrors which may occur if snappy (not python-snappy) is installed (#4908)<commit_after>from __future__ import print_function, division, absolute_import

import bz2
import zlib

from toolz import identity

from ..compatibility import gzip_compress, gzip_decompress, GzipFile, PY2
from ..utils import ignoring


def noop_file(file, **kwargs):
    return file


compress = {'gzip': gzip_compress,
            'zlib': zlib.compress,
            'bz2': bz2.compress,
            None: identity}
decompress = {'gzip': gzip_decompress,
              'zlib': zlib.decompress,
              'bz2': bz2.decompress,
              None: identity}
files = {'gzip': lambda f, **kwargs: GzipFile(fileobj=f, **kwargs),
         None: noop_file}
seekable_files = {None: noop_file}


with ignoring(ImportError, AttributeError):
    # In case snappy is not installed, or another package called snappy that does not implement compress / decompress.
    # For example, SnapPy (https://pypi.org/project/snappy/)
    import snappy
    compress['snappy'] = snappy.compress
    decompress['snappy'] = snappy.decompress


{'fraction_non_alphanumeric': 0.10434782608695652, 'fraction_numerical': 0.008184143222506393, 'mean_word_length': 3.356347438752784, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '1173584', 'n_tokens_mistral': 615, 'n_tokens_neox': 596, 'n_words': 170}