<commit_before>"""General decorators for the landlab library.

General Landlab decorators
++++++++++++++++++++++++++

.. autosummary::
    :toctree: generated/

    ~landlab.utils.decorators.use_file_name_or_kwds
    ~landlab.utils.decorators.use_field_name_or_array
    ~landlab.utils.decorators.make_return_array_immutable
    ~landlab.utils.decorators.deprecated
"""

import os
import warnings
from functools import wraps
import textwrap

import numpy as np
import six

from ..core.model_parameter_loader import load_params


class store_result_in_grid(object):
    def __init__(self, name=None):
        self._attr = name

    def __call__(self, func):
        @wraps(func)
        def _wrapped(grid):
            name = self._attr or '_' + func.__name__
            try:
                getattr(grid, name)
            except AttributeError:
                setattr(grid, name, func(grid))
            finally:
                return getattr(grid, name)

        return _wrapped


class store_result_in_dataset(object):
    def __init__(self, dataset=None, name=None):
        self._dataset = dataset
        self._attr = name

    def __call__(self, func):
        @wraps(func)
        def _wrapped(grid):
            name = self._attr or func.__name__
            if self._dataset:
                ds = getattr(grid, self._dataset)
            else:
                ds = grid

            if name not in ds:
                print 'adding {name} to grid'.format(name=name)
                setattr(grid, self._dataset, ds.update(dict(name=func(grid))))

            return getattr(grid, self._dataset)[name].values

        return _wrapped


def read_only_array(func):
    """Decorate a function so that its return array is read-only.

    Parameters
    ----------
    func : function
        A function that returns a numpy array.

    Returns
    -------
    func
        A wrapped function that returns a read-only numpy array.
    """
    @wraps(func)
    def _wrapped(self, *args, **kwds):
        """Make the returned array read-only."""
        array = func(self, *args, **kwds)
        array.flags.writeable = False
        return array
    return _wrapped


def use_file_name_or_kwds(func):
<commit_msg>Remove print statement.<commit_after>"""General decorators for the landlab library.

General Landlab decorators
++++++++++++++++++++++++++

.. autosummary::
    :toctree: generated/

    ~landlab.utils.decorators.use_file_name_or_kwds
    ~landlab.utils.decorators.use_field_name_or_array
    ~landlab.utils.decorators.make_return_array_immutable
    ~landlab.utils.decorators.deprecated
"""

import os
import warnings
from functools import wraps
import textwrap

import numpy as np
import six

from ..core.model_parameter_loader import load_params


class store_result_in_grid(object):
    def __init__(self, name=None):
        self._attr = name

    def __call__(self, func):
        @wraps(func)
        def _wrapped(grid):
            name = self._attr or '_' + func.__name__
            try:
                getattr(grid, name)
            except AttributeError:
                setattr(grid, name, func(grid))
            finally:
                return getattr(grid, name)

        return _wrapped


class store_result_in_dataset(object):
    def __init__(self, dataset=None, name=None):
        self._dataset = dataset
        self._attr = name

    def __call__(self, func):
        @wraps(func)
        def _wrapped(grid):
            name = self._attr or func.__name__
            if self._dataset:
                ds = getattr(grid, self._dataset)
            else:
                ds = grid

            if name not in ds:
                setattr(grid, self._dataset, ds.update(dict(name=func(grid))))

            return getattr(grid, self._dataset)[name].values

        return _wrapped


def read_only_array(func):
    """Decorate a function so that its return array is read-only.

    Parameters
    ----------
    func : function
        A function that returns a numpy array.

    Returns
    -------
    func
        A wrapped function that returns a read-only numpy array.
    """
    @wraps(func)
    def _wrapped(self, *args, **kwds):
        """Make the returned array read-only."""
        array = func(self, *args, **kwds)
        array.flags.writeable = False
        return array
    return _wrapped


def use_file_name_or_kwds(func):

{'fraction_non_alphanumeric': 0.10474669100867184, 'fraction_numerical': 0.0, 'mean_word_length': 2.232300884955752, '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': '4198358', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1259, 'n_words': 333}