def wrapper(*args, **kwargs): try: # Get the index of the first Series object, if any index = next(arg.index for arg in chain(args, kwargs.values()) if isinstance(arg, _pd_Series)) except StopIteration: # No pandas.Series passed in; short-circuit index = None if index is None: return func(*args, **kwargs) # Use Series' float64 values if pandas, else use values as passed args = [arg.values.astype(float) if isinstance(arg, _pd_Series) else arg for arg in args] kwargs = {k: v.values.astype(float) if isinstance(v, _pd_Series) else v for k, v in kwargs.items()} result = func(*args, **kwargs) # check to see if we got a streaming result first_result = result[0] if isinstance(result, tuple) else result is_streaming_fn_result = not hasattr(first_result, '__len__') if is_streaming_fn_result: return result # Series was passed in, Series gets out; re-apply index if isinstance(result, tuple): # Handle multi-array results such as BBANDS return tuple(_pd_Series(arr, index=index) for arr in result) return _pd_Series(result, index=index)
def wrapper(*args, **kwargs): try: # Get the index of the first Series object, if any index = next(arg.index for arg in chain(args, kwargs.values()) if isinstance(arg, _pd_Series)) except StopIteration: # No pandas.Series passed in; short-circuit index = None if index is None: return func(*args, **kwargs) # Use Series' float64 values if pandas, else use values as passed args = [ arg.values.astype(float) if isinstance(arg, _pd_Series) else arg for arg in args ] kwargs = { k: v.values.astype(float) if isinstance(v, _pd_Series) else v for k, v in kwargs.items() } result = func(*args, **kwargs) # check to see if we got a streaming result first_result = result[0] if isinstance(result, tuple) else result is_streaming_fn_result = not hasattr(first_result, '__len__') if is_streaming_fn_result: return result # Series was passed in, Series gets out; re-apply index if isinstance(result, tuple): # Handle multi-array results such as BBANDS return tuple(_pd_Series(arr, index=index) for arr in result) return _pd_Series(result, index=index)
def wrapper(*args, **kwds): if _pl_Series is not None: use_pl = any(isinstance(arg, _pl_Series) for arg in args) or \ any(isinstance(v, _pl_Series) for v in kwds.values()) else: use_pl = False if _pd_Series is not None: use_pd = any(isinstance(arg, _pd_Series) for arg in args) or \ any(isinstance(v, _pd_Series) for v in kwds.values()) else: use_pd = False if use_pl and use_pd: raise Exception("Cannot mix polars and pandas") # Use float64 values if polars or pandas, else use values as passed if use_pl: _args = [ arg.to_numpy().astype(float) if isinstance( arg, _pl_Series) else arg for arg in args ] _kwds = { k: v.to_numpy().astype(float) if isinstance(v, _pl_Series) else v for k, v in kwds.items() } elif use_pd: index = next(arg.index for arg in chain(args, kwds.values()) if isinstance(arg, _pd_Series)) _args = [ arg.to_numpy().astype(float) if isinstance( arg, _pd_Series) else arg for arg in args ] _kwds = { k: v.to_numpy().astype(float) if isinstance(v, _pd_Series) else v for k, v in kwds.items() } else: _args = args _kwds = kwds result = func(*_args, **_kwds) # check to see if we got a streaming result first_result = result[0] if isinstance(result, tuple) else result is_streaming_fn_result = not hasattr(first_result, '__len__') if is_streaming_fn_result: return result # Series was passed in, Series gets out if use_pl: if isinstance(result, tuple): return tuple(_pl_Series(arr) for arr in result) else: return _pl_Series(result) elif use_pd: if isinstance(result, tuple): return tuple( _pd_Series(arr, index=index) for arr in result) else: return _pd_Series(result, index=index) else: return result