<commit_before>'''
This file Copyright (c) 2013 <NAME> <briancappello at gmail>
'''
from . import func as func_c
from .common import _ta_check_success, MA_Type
from collections import OrderedDict
from cython.operator cimport dereference as deref

cimport numpy as np
cimport libc as lib

__FUNCTION_NAMES = set(func_c.__all__)

__INPUT_ARRAYS_DEFAULTS = { 'open': None,
                            'high': None,
                            'low': None,
                            'close': None,
                            'volume': None }

__INPUT_ARRAYS_KEYS = ['close', 'high', 'low', 'open', 'volume']

# lookup for TALIB input parameters which don't define expected price series inputs
__INPUT_PRICE_SERIES_DEFAULTS = { 'price': 'close',
                                  'price0': 'high',
                                  'price1': 'low',
                                  'periods': None } # only used by MAVP; not a price series!

class Function(object):
    """
    This is a pythonic wrapper around TALIB's abstract interface. It is
    intended to simplify using individual TALIB functions by providing a
    unified interface for setting/controlling input data, setting function
    parameters and retrieving results. Input data consists of a dict of numpy
    arrays, one array for each of open, high, low, close and volume. This can
    be set with the set_input_arrays() method. Which keyed array(s) are used
    as inputs when calling the function is controlled using the input_names
    property.

    This class gets initialized with a TALIB function name and optionally an
    input_arrays dict. It provides the following primary functions for setting
    inputs and retrieving results:

    ---- input_array/TA-function-parameter set-only functions -----
    - set_input_arrays(input_arrays)
    - set_function_args([input_arrays,] [param_args_andor_kwargs])

    Documentation for param_args_andor_kwargs can be seen by printing the
    Function instance or programatically via the info, input_names and
    parameters properties.

    ----- result-returning functions -----
    - the outputs property wraps a method which ensures results are always valid
    - run([input_arrays]) # calls set_input_arrays and returns self.outputs
    - FunctionInstance([input_arrays,] [param_args_andor_kwargs]) # calls set_function_args and returns self.outputs
    """

    def __init__(self, function_name, *args, **kwargs):
        # make sure the function_name is valid and define all of our variables
        self.__name = function_name.upper()
        if self.__name not in __FUNCTION_NAMES:
            raise Exception('%s not supported by TA-LIB.' % self.__name)
        self.__namestr = self.__name
        self.__name = bytes(self.__name, 'ascii')
        self.__info = None
        self.__input_arrays = __INPUT_ARRAYS_DEFAULTS

        # dictionaries of function args. keys are input/opt_input/output parameter names
        self.__input_names = OrderedDict()
        self.__opt_inputs = OrderedDict()
        self.__outputs = OrderedDict()
        self.__outputs_valid = False

        # finish initializing: query the TALIB abstract interface and set arguments
        self.__initialize_function_info()
        self.set_function_args(*args, **kwargs)

    def __initialize_function_info(self):
        # function info
        self.__info = _ta_getFuncInfo(self.__name)

        # inputs (price series names)
        for i in xrange(self.__info.pop('num_inputs')):<commit_msg>minor fix.<commit_after>'''
This file Copyright (c) 2013 <NAME> <briancappello at gmail>
'''
from . import func as func_c
from .common import _ta_check_success, MA_Type
from collections import OrderedDict
from cython.operator cimport dereference as deref

cimport numpy as np
cimport libc as lib

__FUNCTION_NAMES = set(func_c.__all__)

__INPUT_ARRAYS_DEFAULTS = { 'open': None,
                            'high': None,
                            'low': None,
                            'close': None,
                            'volume': None }

__INPUT_ARRAYS_KEYS = ['close', 'high', 'low', 'open', 'volume']

# lookup for TALIB input parameters which don't define expected price series inputs
__INPUT_PRICE_SERIES_DEFAULTS = { 'price': 'close',
                                  'price0': 'high',
                                  'price1': 'low',
                                  'periods': None } # only used by MAVP; not a price series!

class Function(object):
    """
    This is a pythonic wrapper around TALIB's abstract interface. It is
    intended to simplify using individual TALIB functions by providing a
    unified interface for setting/controlling input data, setting function
    parameters and retrieving results. Input data consists of a dict of numpy
    arrays, one array for each of open, high, low, close and volume. This can
    be set with the set_input_arrays() method. Which keyed array(s) are used
    as inputs when calling the function is controlled using the input_names
    property.

    This class gets initialized with a TALIB function name and optionally an
    input_arrays dict. It provides the following primary functions for setting
    inputs and retrieving results:

    ---- input_array/TA-function-parameter set-only functions -----
    - set_input_arrays(input_arrays)
    - set_function_args([input_arrays,] [param_args_andor_kwargs])

    Documentation for param_args_andor_kwargs can be seen by printing the
    Function instance or programatically via the info, input_names and
    parameters properties.

    ----- result-returning functions -----
    - the outputs property wraps a method which ensures results are always valid
    - run([input_arrays]) # calls set_input_arrays and returns self.outputs
    - FunctionInstance([input_arrays,] [param_args_andor_kwargs]) # calls set_function_args and returns self.outputs
    """

    def __init__(self, function_name, *args, **kwargs):
        # make sure the function_name is valid and define all of our variables
        self.__name = function_name.upper()
        if self.__name not in __FUNCTION_NAMES:
            raise Exception('%s not supported by TA-LIB.' % self.__name)
        self.__namestr = self.__name
        if not isinstance(self.__name, bytes):
            self.__name = bytes(self.__name, 'ascii')
        self.__info = None
        self.__input_arrays = __INPUT_ARRAYS_DEFAULTS

        # dictionaries of function args. keys are input/opt_input/output parameter names
        self.__input_names = OrderedDict()
        self.__opt_inputs = OrderedDict()
        self.__outputs = OrderedDict()
        self.__outputs_valid = False

        # finish initializing: query the TALIB abstract interface and set arguments
        self.__initialize_function_info()
        self.set_function_args(*args, **kwargs)

    def __initialize_function_info(self):
        # function info
        self.__info = _ta_getFuncInfo(self.__name)

        # inputs (price series names)
        for i in xrange(self.__info.pop('num_inputs')):
{'fraction_non_alphanumeric': 0.0760715299460687, 'fraction_numerical': 0.0017030939540164632, 'mean_word_length': 2.748404255319149, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4505342', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1837, 'n_words': 662}