QFDataArray

class qf_lib.containers.qf_data_array.QFDataArray(data, coords=None, dims=None, name=None, attrs=None, indexes: Optional[Dict[Hashable, Index]] = None, fastpath=False)[source]

Bases: DataArray

Methods:

concat(objs, dim[, data_vars, coords, ...])

Concatenates different xr.DataArrays and then converts the result to QFDataArray.

create(dates, tickers, fields[, 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.

searchsorted(v[, side, sorter])

Find indices where elements of v should be inserted in a to maintain order.

classmethod concat(objs, dim, data_vars='all', coords='different', compat='equals', positions=None, fill_value=<NA>, join='outer', combine_attrs='override') QFDataArray[source]

Concatenates different xr.DataArrays and then converts the result to QFDataArray.

See also

xr.concat

classmethod create(dates: Union[Sequence[datetime], DatetimeIndex], tickers: Union[Sequence[str], Sequence[Ticker]], fields: Union[Sequence[PriceField], Sequence[str]], data=None, name=None) 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(‘2017-01-01’, 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

Return type:

QFDataArray

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:

QFDataArray

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:

QFDataArray

classmethod from_xr_data_array(xr_data_array: DataArray) QFDataArray[source]

Converts regular xr.DataArray into QFDataArray.

Parameters:

xr_data_array – xr.DataArray with 3 dimensions: dates, tickers and fields.

Return type:

QFDataArray

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 nd-index 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
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