QFDataArray¶

class
qf_lib.containers.qf_data_array.
QFDataArray
(data, coords=None, dims=None, name=None, attrs=None, indexes: Dict[Hashable, pandas.core.indexes.base.Index] = None, fastpath=False)[source]¶ Bases:
xarray.core.dataarray.DataArray
Methods
all
([dim, axis])Reduce this QFDataArray’s data by applying all along some dimension(s).
any
([dim, axis])Reduce this QFDataArray’s data by applying any along some dimension(s).
concat
(objs, dim[, data_vars, coords, …])Concatenates different xr.DataArrays and then converts the result to QFDataArray.
count
([dim, axis])Reduce this QFDataArray’s data by applying count along some dimension(s).
create
(dates, …[, data, name])Helper method for creating a QFDataArray.
cumprod
([dim, axis, skipna])Apply cumprod along some dimension of QFDataArray.
cumsum
([dim, axis, skipna])Apply cumsum along some dimension of QFDataArray.
from_xr_data_array
(xr_data_array)Converts regular xr.DataArray into QFDataArray.
item
(*args)Copy an element of an array to a standard Python scalar and return it.
max
([dim, axis, skipna])Reduce this QFDataArray’s data by applying max along some dimension(s).
mean
([dim, axis, skipna])Reduce this QFDataArray’s data by applying mean along some dimension(s).
median
([dim, axis, skipna])Reduce this QFDataArray’s data by applying median along some dimension(s).
min
([dim, axis, skipna])Reduce this QFDataArray’s data by applying min along some dimension(s).
prod
([dim, axis, skipna])Reduce this QFDataArray’s data by applying prod along some dimension(s).
searchsorted
(v[, side, sorter])Find indices where elements of v should be inserted in a to maintain order.
std
([dim, axis, skipna])Reduce this QFDataArray’s data by applying std along some dimension(s).
sum
([dim, axis, skipna])Reduce this QFDataArray’s data by applying sum along some dimension(s).
var
([dim, axis, skipna])Reduce this QFDataArray’s data by applying var along some dimension(s).

all
(dim=None, axis=None, **kwargs)¶ Reduce this QFDataArray’s data by applying all along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply all.
axis (int or sequence of int, optional) – Axis(es) over which to apply all. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then all is calculated over axes.
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating all on this object’s data.
 Returns
reduced – New QFDataArray object with all applied to its data and the indicated dimension(s) removed.
 Return type

any
(dim=None, axis=None, **kwargs)¶ Reduce this QFDataArray’s data by applying any along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply any.
axis (int or sequence of int, optional) – Axis(es) over which to apply any. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then any is calculated over axes.
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating any on this object’s data.
 Returns
reduced – New QFDataArray object with any applied to its data and the indicated dimension(s) removed.
 Return type

classmethod
concat
(objs, dim, data_vars='all', coords='different', compat='equals', positions=None, fill_value=<NA>, join='outer', combine_attrs='override') → qf_lib.containers.qf_data_array.QFDataArray[source]¶ Concatenates different xr.DataArrays and then converts the result to QFDataArray.
See also
xr.concat()

count
(dim=None, axis=None, **kwargs)¶ Reduce this QFDataArray’s data by applying count along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply count.
axis (int or sequence of int, optional) – Axis(es) over which to apply count. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then count is calculated over axes.
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating count on this object’s data.
 Returns
reduced – New QFDataArray object with count applied to its data and the indicated dimension(s) removed.
 Return type

classmethod
create
(dates: Union[Sequence[datetime.datetime], pandas.core.indexes.datetimes.DatetimeIndex], tickers: Union[Sequence[str], Sequence[qf_lib.common.tickers.tickers.Ticker]], fields: Union[Sequence[qf_lib.common.enums.price_field.PriceField], Sequence[str]], data=None, name=None) → qf_lib.containers.qf_data_array.QFDataArray[source]¶ Helper method for creating a QFDataArray. __init__() methods can’t be used for that, because its signature must be the same as the signature of xr.DataArray.__init__().
Example: a = QFDataArray.create(dates=pd.date_range(‘20170101’, periods=3), tickers=[‘a’, ‘b’], fields=[‘field’], data=[[[1.0], [2.0]], [[3.0], [4.0]], [[5.0], [6.0]]])
 Parameters
dates – dates index (labels)
tickers – tickers index (labels)
fields – fields index (labels)
data – data that should be put in the array (it’s dimensions must be in the proper order: dates, tickers, fields).
name – name of the QFDataArray
 Returns
 Return type

cumprod
(dim=None, axis=None, skipna=None, **kwargs)¶ Apply cumprod along some dimension of QFDataArray.
 Parameters
dim (str or sequence of str, optional) – Dimension over which to apply cumprod.
axis (int or sequence of int, optional) – Axis over which to apply cumprod. Only one of the ‘dim’ and ‘axis’ arguments can be supplied.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to cumprod.
 Returns
cumvalue – New QFDataArray object with cumprod applied to its data along the indicated dimension.
 Return type

cumsum
(dim=None, axis=None, skipna=None, **kwargs)¶ Apply cumsum along some dimension of QFDataArray.
 Parameters
dim (str or sequence of str, optional) – Dimension over which to apply cumsum.
axis (int or sequence of int, optional) – Axis over which to apply cumsum. Only one of the ‘dim’ and ‘axis’ arguments can be supplied.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to cumsum.
 Returns
cumvalue – New QFDataArray object with cumsum applied to its data along the indicated dimension.
 Return type

classmethod
from_xr_data_array
(xr_data_array: xarray.core.dataarray.DataArray) → qf_lib.containers.qf_data_array.QFDataArray[source]¶ Converts regular xr.DataArray into QFDataArray.
 Parameters
xr_data_array – xr.DataArray with 3 dimensions: dates, tickers and fields.
 Returns
 Return type

item
(*args)¶ Copy an element of an array to a standard Python scalar and return it.
 Parameters
*args (Arguments (variable number and type)) –
none: in this case, the method only works for arrays with one element (a.size == 1), which element is copied into a standard Python scalar object and returned.
int_type: this argument is interpreted as a flat index into the array, specifying which element to copy and return.
tuple of int_types: functions as does a single int_type argument, except that the argument is interpreted as an ndindex into the array.
 Returns
z – A copy of the specified element of the array as a suitable Python scalar
 Return type
Standard Python scalar object
Notes
When the data type of a is longdouble or clongdouble, item() returns a scalar array object because there is no available Python scalar that would not lose information. Void arrays return a buffer object for item(), unless fields are defined, in which case a tuple is returned.
item is very similar to a[args], except, instead of an array scalar, a standard Python scalar is returned. This can be useful for speeding up access to elements of the array and doing arithmetic on elements of the array using Python’s optimized math.
Examples
>>> np.random.seed(123) >>> x = np.random.randint(9, size=(3, 3)) >>> x array([[2, 2, 6], [1, 3, 6], [1, 0, 1]]) >>> x.item(3) 1 >>> x.item(7) 0 >>> x.item((0, 1)) 2 >>> x.item((2, 2)) 1

max
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying max along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply max.
axis (int or sequence of int, optional) – Axis(es) over which to apply max. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then max is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating max on this object’s data.
 Returns
reduced – New QFDataArray object with max applied to its data and the indicated dimension(s) removed.
 Return type

mean
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying mean along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply mean.
axis (int or sequence of int, optional) – Axis(es) over which to apply mean. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then mean is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating mean on this object’s data.
 Returns
reduced – New QFDataArray object with mean applied to its data and the indicated dimension(s) removed.
 Return type

median
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying median along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply median.
axis (int or sequence of int, optional) – Axis(es) over which to apply median. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then median is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating median on this object’s data.
 Returns
reduced – New QFDataArray object with median applied to its data and the indicated dimension(s) removed.
 Return type

min
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying min along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply min.
axis (int or sequence of int, optional) – Axis(es) over which to apply min. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then min is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating min on this object’s data.
 Returns
reduced – New QFDataArray object with min applied to its data and the indicated dimension(s) removed.
 Return type

prod
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying prod along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply prod.
axis (int or sequence of int, optional) – Axis(es) over which to apply prod. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then prod is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
min_count (int, default: None) – The required number of valid values to perform the operation. If fewer than min_count nonNA values are present the result will be NA. Only used if skipna is set to True or defaults to True for the array’s dtype. New in version 0.10.8: Added with the default being None. Changed in version 0.17.0: if specified on an integer array and skipna=True, the result will be a float array.
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating prod on this object’s data.
 Returns
reduced – New QFDataArray object with prod applied to its data and the indicated dimension(s) removed.
 Return type

searchsorted
(v, side='left', sorter=None)¶ Find indices where elements of v should be inserted in a to maintain order.
For full documentation, see numpy.searchsorted
See also
numpy.searchsorted()
equivalent function

std
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying std along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply std.
axis (int or sequence of int, optional) – Axis(es) over which to apply std. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then std is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating std on this object’s data.
 Returns
reduced – New QFDataArray object with std applied to its data and the indicated dimension(s) removed.
 Return type

sum
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying sum along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply sum.
axis (int or sequence of int, optional) – Axis(es) over which to apply sum. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then sum is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
min_count (int, default: None) – The required number of valid values to perform the operation. If fewer than min_count nonNA values are present the result will be NA. Only used if skipna is set to True or defaults to True for the array’s dtype. New in version 0.10.8: Added with the default being None. Changed in version 0.17.0: if specified on an integer array and skipna=True, the result will be a float array.
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating sum on this object’s data.
 Returns
reduced – New QFDataArray object with sum applied to its data and the indicated dimension(s) removed.
 Return type

var
(dim=None, axis=None, skipna=None, **kwargs)¶ Reduce this QFDataArray’s data by applying var along some dimension(s).
 Parameters
dim (str or sequence of str, optional) – Dimension(s) over which to apply var.
axis (int or sequence of int, optional) – Axis(es) over which to apply var. Only one of the ‘dim’ and ‘axis’ arguments can be supplied. If neither are supplied, then var is calculated over axes.
skipna (bool, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
**kwargs (dict) – Additional keyword arguments passed on to the appropriate array function for calculating var on this object’s data.
 Returns
reduced – New QFDataArray object with var applied to its data and the indicated dimension(s) removed.
 Return type
