pandera.typing.xarray.DataArray

class pandera.typing.xarray.DataArray(data=<NA>, coords=None, dims=None, name=None, attrs=None, indexes=None, fastpath=False)[source]

Annotation-only generic for xarray.DataArray.

Attributes

T

attrs

Dictionary storing arbitrary metadata with this array.

chunks

Tuple of block lengths for this dataarray's data, in order of dimensions, or None if the underlying data is not a dask array.

chunksizes

Mapping from dimension names to block lengths for this dataarray's data.

coords

Mapping of DataArray objects corresponding to coordinate variables.

data

The DataArray's data as an array.

dims

Tuple of dimension names associated with this array.

dt

alias of CombinedDatetimelikeAccessor[DataArray]

dtype

Data-type of the array’s elements.

encoding

Dictionary of format-specific settings for how this array should be serialized.

imag

The imaginary part of the array.

indexes

Mapping of pandas.Index objects used for label based indexing.

loc

Attribute for location based indexing like pandas.

name

The name of this array.

nbytes

Total bytes consumed by the elements of this DataArray's data.

ndim

Number of array dimensions.

real

The real part of the array.

shape

Tuple of array dimensions.

size

Number of elements in the array.

sizes

Ordered mapping from dimension names to lengths.

str

alias of StringAccessor[DataArray]

values

The array's data converted to numpy.ndarray.

variable

Low level interface to the Variable object for this DataArray.

xindexes

Mapping of Index objects used for label based indexing.

Methods

item(*args)[source]

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

zStandard Python scalar object

A copy of the specified element of the array as a suitable Python scalar

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

>>> import numpy as np
>>> 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

For an array with object dtype, elements are returned as-is.

>>> a = np.array([np.int64(1)], dtype=object)
>>> a.item() #return np.int64
np.int64(1)
searchsorted(v, side='left', sorter=None)[source]

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