API Reference¶
Table of Contents
Custom Pandas dtypes for values with SI units.
Classes:
|
|
Numpy dtype representing a temperature in degrees Celsius. |
|
|
|
|
Holder for Temperatures. |
Functions:
|
Convert values to a |
-
class
Celsius
(value)[source]¶ Bases:
UserFloat
float
subclass representing a temperature in Celsius.Convert a string or number to a floating point number, if possible.
Methods:
__abs__
()Return
abs(self)
.__add__
(other)Return
self + value
.__bool__
()True if self != 0.
__ceil__
()Finds the least Integral >= self.
complex(self) == complex(float(self), 0)
__divmod__
(other)Return
divmod(self, value)
.__eq__
(other)Return
self == other
.Return
float(self)
.Finds the greatest Integral <= self.
__floordiv__
(other)Return
self // value
.__ge__
(other)Return
self >= other
.__gt__
(other)Return
self > other
.__int__
()Return
int(self)
.__le__
(other)Return
self <= other
.__lt__
(other)Return
self < other
.__mod__
(other)Return
self % value
.__mul__
(other)Return
self * value
.__ne__
(other)Return
self != other
.__neg__
()Return
- self
.__pos__
()Return
+ self
.__pow__
(other[, mod])Return
pow(self, value, mod)
.__radd__
(other)Return
value + self
.__rdivmod__
(other)Return
divmod(value, self)
.__repr__
()Return a string representation of the temperature.
__rfloordiv__
(other)Return
value // self
.__rmod__
(other)Return
value % self
.__rmul__
(other)Return
value * self
.__round__
([ndigits])Rounds self to ndigits decimal places, defaulting to 0.
__rpow__
(other[, mod])Return
pow(value, self, mod)
.__rsub__
(other)Return
value - self
.__rtruediv__
(other)Return
value / self
.__str__
()Return the temperature as a string.
__sub__
(other)Return
value - self
.__truediv__
(other)Return
self / value
.trunc(self): Truncates self to an Integral.
Conjugate is a no-op for Reals.
fromhex
(_UserFloat__s)- rtype
~_F
hex
()- rtype
- rtype
Attributes:
Real numbers have no imaginary component.
Real numbers are their real component.
-
__add__
(other)¶ Return
self + value
.- Return type
~_F
-
__ceil__
()¶ Finds the least Integral >= self.
-
__complex__
()¶ complex(self) == complex(float(self), 0)
-
__divmod__
(other)¶ Return
divmod(self, value)
.- Return type
Tuple
[~_F
,~_F
]
-
__float__
()¶ Return
float(self)
.- Return type
-
__floor__
()¶ Finds the greatest Integral <= self.
-
__floordiv__
(other)¶ Return
self // value
.- Return type
~_F
-
__mod__
(other)¶ Return
self % value
.- Return type
~_F
-
__mul__
(other)¶ Return
self * value
.- Return type
~_F
-
__neg__
()¶ Return
- self
.- Return type
~_F
-
__pos__
()¶ Return
+ self
.- Return type
~_F
-
__pow__
(other, mod=None)¶ Return
pow(self, value, mod)
.- Return type
~_F
-
__radd__
(other)¶ Return
value + self
.- Return type
~_F
-
__rdivmod__
(other)¶ Return
divmod(value, self)
.- Return type
Tuple
[~_F
,~_F
]
-
__rfloordiv__
(other)¶ Return
value // self
.- Return type
~_F
-
__rmod__
(other)¶ Return
value % self
.- Return type
~_F
-
__rmul__
(other)¶ Return
value * self
.- Return type
~_F
-
__round__
(ndigits=None)¶ Rounds self to ndigits decimal places, defaulting to 0.
If ndigits is omitted or None, returns an Integral, otherwise returns a Real. Rounds half toward even.
-
__rpow__
(other, mod=None)¶ Return
pow(value, self, mod)
.- Return type
~_F
-
__rsub__
(other)¶ Return
value - self
.- Return type
~_F
-
__rtruediv__
(other)¶ Return
value / self
.- Return type
~_F
-
__slots__
= ()¶
-
__sub__
(other)¶ Return
value - self
.- Return type
~_F
-
__truediv__
(other)¶ Return
self / value
.- Return type
~_F
-
__trunc__
()¶ trunc(self): Truncates self to an Integral.
- Returns an Integral i such that:
i>0 iff self>0;
abs(i) <= abs(self);
for any Integral j satisfying the first two conditions, abs(i) >= abs(j) [i.e. i has “maximal” abs among those].
i.e. “truncate towards 0”.
- Return type
-
_abc_impl
= <_abc_data object>¶
-
conjugate
()¶ Conjugate is a no-op for Reals.
-
classmethod
fromhex
(_UserFloat__s)¶ - Return type
~_F
-
property
imag
¶ Real numbers have no imaginary component.
-
property
real
¶ Real numbers are their real component.
-
class
CelsiusType
[source]¶ Bases:
ExtensionDtype
Numpy dtype representing a temperature in degrees Celsius.
Methods:
__eq__
(other)Check whether ‘other’ is equal to self.
__ne__
(other)Return self!=value.
__str__
()Return str(self).
_get_common_dtype
(dtypes)Return the common dtype, if one exists.
Return the array type associated with this dtype.
construct_from_string
(string)Construct a
CelsiusType
from a string.is_dtype
(dtype)Check if we match ‘dtype’.
Attributes:
Whether this dtype should be considered boolean.
Whether columns with this dtype should be considered numeric.
Default NA value to use for this type.
Ordered list of field names, or None if there are no fields.
Classes:
alias of
builtins.float
alias of
TemperatureBase
-
__eq__
(other)¶ Check whether ‘other’ is equal to self.
By default, ‘other’ is considered equal if either
it’s a string matching ‘self.name’.
it’s an instance of this type and all of the attributes in
self._metadata
are equal between self and other.
other : Any
bool
- Return type
-
_get_common_dtype
(dtypes)¶ Return the common dtype, if one exists.
Used in find_common_type implementation. This is for example used to determine the resulting dtype in a concat operation.
If no common dtype exists, return None (which gives the other dtypes the chance to determine a common dtype). If all dtypes in the list return None, then the common dtype will be “object” dtype (this means it is never needed to return “object” dtype from this method itself).
- dtypeslist of dtypes
The dtypes for which to determine a common dtype. This is a list of np.dtype or ExtensionDtype instances.
Common dtype (np.dtype or ExtensionDtype) or None
-
property
_is_boolean
¶ Whether this dtype should be considered boolean.
By default, ExtensionDtypes are assumed to be non-numeric. Setting this to True will affect the behavior of several places, e.g.
is_bool
boolean indexing
- Return type
-
property
_is_numeric
¶ Whether columns with this dtype should be considered numeric.
By default ExtensionDtypes are assumed to be non-numeric. They’ll be excluded from operations that exclude non-numeric columns, like (groupby) reductions, plotting, etc.
- Return type
-
_record_type
¶ alias of
builtins.float
-
classmethod
construct_array_type
()[source]¶ Return the array type associated with this dtype.
type
- Return type
Type
[TemperatureArray
]
-
classmethod
construct_from_string
(string)[source]¶ Construct a
CelsiusType
from a string.- Parameters
string
-
classmethod
is_dtype
(dtype)¶ Check if we match ‘dtype’.
- dtypeobject
The object to check.
bool
The default implementation is True if
cls.construct_from_string(dtype)
is an instance ofcls
.dtype
is an object and is an instance ofcls
dtype
has adtype
attribute, and any of the above conditions is true fordtype.dtype
.
- Return type
-
property
na_value
¶ Default NA value to use for this type.
This is used in e.g. ExtensionArray.take. This should be the user-facing “boxed” version of the NA value, not the physical NA value for storage. e.g. for JSONArray, this is an empty dictionary.
- Return type
-
property
names
¶ Ordered list of field names, or None if there are no fields.
This is for compatibility with NumPy arrays, and may be removed in the future.
-
type
¶ alias of
TemperatureBase
-
-
class
Fahrenheit
(value=0.0)[source]¶ Bases:
UserFloat
float
subclass representing a temperature in Fahrenheit.Convert a string or number to a floating point number, if possible.
Methods:
__abs__
()Return
abs(self)
.__add__
(other)Return
self + value
.__bool__
()True if self != 0.
__ceil__
()Finds the least Integral >= self.
complex(self) == complex(float(self), 0)
__divmod__
(other)Return
divmod(self, value)
.__eq__
(other)Return
self == other
.Return
float(self)
.Finds the greatest Integral <= self.
__floordiv__
(other)Return
self // value
.__ge__
(other)Return
self >= other
.__gt__
(other)Return
self > other
.__int__
()Return
int(self)
.__le__
(other)Return
self <= other
.__lt__
(other)Return
self < other
.__mod__
(other)Return
self % value
.__mul__
(other)Return
self * value
.__ne__
(other)Return
self != other
.__neg__
()Return
- self
.__pos__
()Return
+ self
.__pow__
(other[, mod])Return
pow(self, value, mod)
.__radd__
(other)Return
value + self
.__rdivmod__
(other)Return
divmod(value, self)
.__repr__
()Return a string representation of the temperature.
__rfloordiv__
(other)Return
value // self
.__rmod__
(other)Return
value % self
.__rmul__
(other)Return
value * self
.__round__
([ndigits])Rounds self to ndigits decimal places, defaulting to 0.
__rpow__
(other[, mod])Return
pow(value, self, mod)
.__rsub__
(other)Return
value - self
.__rtruediv__
(other)Return
value / self
.__str__
()Return the temperature as a string.
__sub__
(other)Return
value - self
.__truediv__
(other)Return
self / value
.trunc(self): Truncates self to an Integral.
Conjugate is a no-op for Reals.
fromhex
(_UserFloat__s)- rtype
~_F
hex
()- rtype
- rtype
Attributes:
Real numbers have no imaginary component.
Real numbers are their real component.
-
__add__
(other)¶ Return
self + value
.- Return type
~_F
-
__ceil__
()¶ Finds the least Integral >= self.
-
__complex__
()¶ complex(self) == complex(float(self), 0)
-
__divmod__
(other)¶ Return
divmod(self, value)
.- Return type
Tuple
[~_F
,~_F
]
-
__float__
()¶ Return
float(self)
.- Return type
-
__floor__
()¶ Finds the greatest Integral <= self.
-
__floordiv__
(other)¶ Return
self // value
.- Return type
~_F
-
__mod__
(other)¶ Return
self % value
.- Return type
~_F
-
__mul__
(other)¶ Return
self * value
.- Return type
~_F
-
__neg__
()¶ Return
- self
.- Return type
~_F
-
__pos__
()¶ Return
+ self
.- Return type
~_F
-
__pow__
(other, mod=None)¶ Return
pow(self, value, mod)
.- Return type
~_F
-
__radd__
(other)¶ Return
value + self
.- Return type
~_F
-
__rdivmod__
(other)¶ Return
divmod(value, self)
.- Return type
Tuple
[~_F
,~_F
]
-
__rfloordiv__
(other)¶ Return
value // self
.- Return type
~_F
-
__rmod__
(other)¶ Return
value % self
.- Return type
~_F
-
__rmul__
(other)¶ Return
value * self
.- Return type
~_F
-
__round__
(ndigits=None)¶ Rounds self to ndigits decimal places, defaulting to 0.
If ndigits is omitted or None, returns an Integral, otherwise returns a Real. Rounds half toward even.
-
__rpow__
(other, mod=None)¶ Return
pow(value, self, mod)
.- Return type
~_F
-
__rsub__
(other)¶ Return
value - self
.- Return type
~_F
-
__rtruediv__
(other)¶ Return
value / self
.- Return type
~_F
-
__slots__
= ()¶
-
__sub__
(other)¶ Return
value - self
.- Return type
~_F
-
__truediv__
(other)¶ Return
self / value
.- Return type
~_F
-
__trunc__
()¶ trunc(self): Truncates self to an Integral.
- Returns an Integral i such that:
i>0 iff self>0;
abs(i) <= abs(self);
for any Integral j satisfying the first two conditions, abs(i) >= abs(j) [i.e. i has “maximal” abs among those].
i.e. “truncate towards 0”.
- Return type
-
_abc_impl
= <_abc_data object>¶
-
conjugate
()¶ Conjugate is a no-op for Reals.
-
classmethod
fromhex
(_UserFloat__s)¶ - Return type
~_F
-
property
imag
¶ Real numbers have no imaginary component.
-
property
real
¶ Real numbers are their real component.
-
class
TemperatureArray
(data, dtype=None, copy=False)[source]¶ Bases:
BaseArray
Holder for Temperatures.
TemperatureArray is a container for Temperatures. It satisfies pandas’ extension array interface, and so can be stored inside
pandas.Series
andpandas.DataFrame
.Attributes:
- rtype
ExtensionArray
The dtype for this extension array,
CelsiusType
.The missing value.
The number of bytes needed to store this object in memory.
Return a tuple of the array dimensions.
The number of elements in the array.
Methods:
__abs__
()__add__
(other)__and__
(other)__contains__
(item)Return for item in self.
__delitem__
(where)__divmod__
(other)__eq__
(other)Return for self == other (element-wise equality).
__floordiv__
(other)__ge__
(other)Return self>=value.
__getitem__
(item)Select a subset of self.
__gt__
(other)Return self>value.
__iadd__
(other)__iand__
(other)__ifloordiv__
(other)__ilshift__
(other)__imatmul__
(other)__imod__
(other)__imul__
(other)__ior__
(other)__ipow__
(other)__irshift__
(other)__isub__
(other)__iter__
()Iterate over elements of the array.
__itruediv__
(other)__ixor__
(other)__le__
(other)Return self<=value.
__len__
()Returns the length of this array.
__lshift__
(other)__lt__
(other)Return self<value.
__matmul__
(other)__mod__
(other)__mul__
(other)__ne__
(other)Return for self != other (element-wise in-equality).
__neg__
()__or__
(other)__pos__
()__pow__
(other)__radd__
(other)__rand__
(other)__rdivmod__
(other)__repr__
()Return repr(self).
__rfloordiv__
(other)__rlshift__
(other)__rmatmul__
(other)__rmod__
(other)__rmul__
(other)__ror__
(other)__rpow__
(other)__rrshift__
(other)__rshift__
(other)__rsub__
(other)__rtruediv__
(other)__rxor__
(other)__setitem__
(key, value)Set one or more values inplace.
__sub__
(other)__truediv__
(other)__xor__
(other)_concat_same_type
(to_concat)Concatenate multiple arrays.
_formatter
([boxed])Formatting function for scalar values.
_from_factorized
(values, original)Reconstruct an ExtensionArray after factorization.
_from_ndarray
(data[, copy])Zero-copy construction of a BaseArray from an ndarray.
_from_sequence
(scalars[, dtype, copy])Construct a new ExtensionArray from a sequence of scalars.
_from_sequence_of_strings
(strings, *[, …])Construct a new ExtensionArray from a sequence of strings.
_isstringslice
(where)_reduce
(name, *[, skipna])Return a scalar result of performing the reduction operation.
Return values for sorting.
Return an array and missing value suitable for factorization.
append
(value)Append a value to this TemperatureArray.
argmax
()Return the index of maximum value.
argmin
()Return the index of minimum value.
argsort
([ascending, kind])Return the indices that would sort this array.
astype
(dtype[, copy])Returns the array with its values as the given dtype.
copy
([deep])Return a copy of the array.
dropna
()Return ExtensionArray without NA values.
equals
(other)Return if another array is equivalent to this array.
factorize
([na_sentinel])Encode the extension array as an enumerated type.
fillna
([value, method, limit])Fill NA/NaN values using the specified method.
isin
(other)Check whether elements of self are in other.
isna
()Indicator for whether each element is missing.
ravel
([order])Return a flattened view on this array.
repeat
(repeats[, axis])Repeat elements of a ExtensionArray.
searchsorted
(value[, side, sorter])Find indices where elements should be inserted to maintain order.
setitem
(indexer, value)Set the ‘value’ inplace.
shift
([periods, fill_value])Shift values by desired number.
take
(indices[, allow_fill, fill_value])Take elements from an array.
to_numpy
([dtype, copy, na_value])Convert to a NumPy ndarray.
tolist
()Convert the array to a Python list.
transpose
(*axes)Return a transposed view on this array.
unique
()Compute the ExtensionArray of unique values.
view
([dtype])Return a view on the array.
-
property
T
¶ - Return type
ExtensionArray
-
__abs__
()¶
-
__add__
(other)¶
-
__and__
(other)¶
-
__delitem__
(where)¶
-
__divmod__
(other)¶
-
__eq__
(other)¶ Return for self == other (element-wise equality).
-
__floordiv__
(other)¶
-
__ge__
(other)¶ Return self>=value.
-
__getitem__
(item)[source]¶ Select a subset of self.
- Parameters
item (
Union
[int
,slice
,ndarray
]) –int: The position in ‘self’ to get.
slice: A slice object, where ‘start’, ‘stop’, and ‘step’ are integers or None.
ndarray: A 1-d boolean NumPy ndarray the same length as ‘self’
- Return type
scalar or ExtensionArray
Note
For scalar
item
, return a scalar value suitable for the array’s type. This should be an instance ofself.dtype.type
.For slice
key
, return an instance ofExtensionArray
, even if the slice is length 0 or 1.For a boolean mask, return an instance of
ExtensionArray
, filtered to the values whereitem
is True.
-
__gt__
(other)¶ Return self>value.
-
__iadd__
(other)¶
-
__iand__
(other)¶
-
__ifloordiv__
(other)¶
-
__ilshift__
(other)¶
-
__imatmul__
(other)¶
-
__imod__
(other)¶
-
__imul__
(other)¶
-
__invert__
()¶
-
__ior__
(other)¶
-
__ipow__
(other)¶
-
__irshift__
(other)¶
-
__isub__
(other)¶
-
__iter__
()¶ Iterate over elements of the array.
-
__itruediv__
(other)¶
-
__ixor__
(other)¶
-
__le__
(other)¶ Return self<=value.
-
__lshift__
(other)¶
-
__lt__
(other)¶ Return self<value.
-
__matmul__
(other)¶
-
__mod__
(other)¶
-
__mul__
(other)¶
-
__ne__
(other)¶ Return for self != other (element-wise in-equality).
-
__neg__
()¶
-
__or__
(other)¶
-
__pos__
()¶
-
__pow__
(other)¶
-
__radd__
(other)¶
-
__rand__
(other)¶
-
__rdivmod__
(other)¶
-
__rfloordiv__
(other)¶
-
__rlshift__
(other)¶
-
__rmatmul__
(other)¶
-
__rmod__
(other)¶
-
__rmul__
(other)¶
-
__ror__
(other)¶
-
__rpow__
(other)¶
-
__rrshift__
(other)¶
-
__rshift__
(other)¶
-
__rsub__
(other)¶
-
__rtruediv__
(other)¶
-
__rxor__
(other)¶
-
__setitem__
(key, value)¶ Set one or more values inplace.
This method is not required to satisfy the pandas extension array interface.
- keyint, ndarray, or slice
When called from, e.g.
Series.__setitem__
,key
will be one ofscalar int
ndarray of integers.
boolean ndarray
slice object
- valueExtensionDtype.type, Sequence[ExtensionDtype.type], or object
value or values to be set of
key
.
None
-
__sub__
(other)¶
-
__truediv__
(other)¶
-
__xor__
(other)¶
-
_can_hold_na
= True¶
-
classmethod
_concat_same_type
(to_concat)¶ Concatenate multiple arrays.
- Parameters
to_concat (
Sequence
[ABCExtensionArray
]) – sequence of this type- Return type
ABCExtensionArray
-
_dtype
: Type[pandas.core.dtypes.base.ExtensionDtype] = <si_unit_pandas.temperature.CelsiusType object>¶
-
_formatter
(boxed=False)¶ Formatting function for scalar values.
This is used in the default ‘__repr__’. The returned formatting function receives instances of your scalar type.
- boxedbool, default False
An indicated for whether or not your array is being printed within a Series, DataFrame, or Index (True), or just by itself (False). This may be useful if you want scalar values to appear differently within a Series versus on its own (e.g. quoted or not).
- Callable[[Any], str]
A callable that gets instances of the scalar type and returns a string. By default,
repr()
is used whenboxed=False
andstr()
is used whenboxed=True
.
-
_formatting_values
()¶
-
classmethod
_from_factorized
(values, original)¶ Reconstruct an ExtensionArray after factorization.
- Parameters
values (
ndarray
) – An integer ndarray with the factorized values.original (
ExtensionArray
) – The original ExtensionArray that factorize was called on.
See also
pandas.pandas.api.extensions.ExtensionArray.factorize()
-
classmethod
_from_ndarray
(data, copy=False)¶ Zero-copy construction of a BaseArray from an ndarray.
-
classmethod
_from_sequence
(scalars, dtype=None, copy=False)¶ Construct a new ExtensionArray from a sequence of scalars.
- Parameters
scalars (
Iterable
) – Each element will be an instance of the scalar type for this array,cls.dtype.type
.dtype (dtype, optional) – Construct for this particular dtype. This should be a Dtype compatible with the ExtensionArray. Default
None
.copy (
bool
) – If True, copy the underlying data. DefaultFalse
.
-
classmethod
_from_sequence_of_strings
(strings, *, dtype=None, copy=False)¶ Construct a new ExtensionArray from a sequence of strings.
New in version 0.24.0.
- stringsSequence
Each element will be an instance of the scalar type for this array,
cls.dtype.type
.- dtypedtype, optional
Construct for this particular dtype. This should be a Dtype compatible with the ExtensionArray.
- copybool, default False
If True, copy the underlying data.
ExtensionArray
-
_isstringslice
(where)¶
-
property
_parser
¶
-
_reduce
(name, *, skipna=True, **kwargs)¶ Return a scalar result of performing the reduction operation.
- namestr
Name of the function, supported values are: { any, all, min, max, sum, mean, median, prod, std, var, sem, kurt, skew }.
- skipnabool, default True
If True, skip NaN values.
- **kwargs
Additional keyword arguments passed to the reduction function. Currently, ddof is the only supported kwarg.
scalar
TypeError : subclass does not define reductions
-
_typ
= 'extension'¶
-
_values_for_argsort
()¶ Return values for sorting.
- ndarray
The transformed values should maintain the ordering between values within the array.
ExtensionArray.argsort : Return the indices that would sort this array.
- Return type
-
_values_for_factorize
()¶ Return an array and missing value suitable for factorization.
values : ndarray
An array suitable for factorization. This should maintain order and be a supported dtype (Float64, Int64, UInt64, String, Object). By default, the extension array is cast to object dtype.
- na_valueobject
The value in values to consider missing. This will be treated as NA in the factorization routines, so it will be coded as na_sentinel and not included in uniques. By default,
np.nan
is used.
The values returned by this method are also used in
pandas.util.hash_pandas_object()
.
-
argmax
()¶ Return the index of maximum value.
In case of multiple occurrences of the maximum value, the index corresponding to the first occurrence is returned.
int
ExtensionArray.argmin
-
argmin
()¶ Return the index of minimum value.
In case of multiple occurrences of the minimum value, the index corresponding to the first occurrence is returned.
int
ExtensionArray.argmax
-
argsort
(ascending=True, kind='quicksort', *args, **kwargs)¶ Return the indices that would sort this array.
- Parameters
*args and **kwargs are passed through to
numpy.argsort()
.- Return type
- Returns
Array of indices that sort
self
. If NaN values are contained, NaN values are placed at the end.
See also
numpy.argsort
: Sorting implementation used internally.
-
copy
(deep=False)¶ Return a copy of the array.
-
dropna
()¶ Return ExtensionArray without NA values.
valid : ExtensionArray
-
property
dtype
¶ The dtype for this extension array,
CelsiusType
.
-
equals
(other)¶ Return if another array is equivalent to this array.
Equivalent means that both arrays have the same shape and dtype, and all values compare equal. Missing values in the same location are considered equal (in contrast with normal equality).
- otherExtensionArray
Array to compare to this Array.
- boolean
Whether the arrays are equivalent.
- Return type
-
factorize
(na_sentinel=- 1)¶ Encode the extension array as an enumerated type.
- na_sentinelint, default -1
Value to use in the codes array to indicate missing values.
- codesndarray
An integer NumPy array that’s an indexer into the original ExtensionArray.
- uniquesExtensionArray
An ExtensionArray containing the unique values of self.
Note
uniques will not contain an entry for the NA value of the ExtensionArray if there are any missing values present in self.
factorize : Top-level factorize method that dispatches here.
pandas.factorize()
offers a sort keyword as well.
-
fillna
(value=None, method=None, limit=None)¶ Fill NA/NaN values using the specified method.
- valuescalar, array-like
If a scalar value is passed it is used to fill all missing values. Alternatively, an array-like ‘value’ can be given. It’s expected that the array-like have the same length as ‘self’.
- method{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None
Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use NEXT valid observation to fill gap.
- limitint, default None
If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled.
- ExtensionArray
With NA/NaN filled.
-
isna
()¶ Indicator for whether each element is missing.
-
property
na_value
¶ The missing value.
Example:
>>> BaseArray([]).na_value numpy.nan
-
ravel
(order='C')¶ Return a flattened view on this array.
order : {None, ‘C’, ‘F’, ‘A’, ‘K’}, default ‘C’
ExtensionArray
Because ExtensionArrays are 1D-only, this is a no-op.
The “order” argument is ignored, is for compatibility with NumPy.
- Return type
ExtensionArray
-
repeat
(repeats, axis=None)¶ Repeat elements of a ExtensionArray.
Returns a new ExtensionArray where each element of the current ExtensionArray is repeated consecutively a given number of times.
- repeatsint or array of ints
The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty ExtensionArray.
- axisNone
Must be
None
. Has no effect but is accepted for compatibility with numpy.
- repeated_arrayExtensionArray
Newly created ExtensionArray with repeated elements.
Series.repeat : Equivalent function for Series. Index.repeat : Equivalent function for Index. numpy.repeat : Similar method for
numpy.ndarray
. ExtensionArray.take : Take arbitrary positions.>>> cat = pd.Categorical(['a', 'b', 'c']) >>> cat ['a', 'b', 'c'] Categories (3, object): ['a', 'b', 'c'] >>> cat.repeat(2) ['a', 'a', 'b', 'b', 'c', 'c'] Categories (3, object): ['a', 'b', 'c'] >>> cat.repeat([1, 2, 3]) ['a', 'b', 'b', 'c', 'c', 'c'] Categories (3, object): ['a', 'b', 'c']
-
searchsorted
(value, side='left', sorter=None)¶ Find indices where elements should be inserted to maintain order.
New in version 0.24.0.
Find the indices into a sorted array self (a) such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved.
Assuming that self is sorted:
side
returned index i satisfies
left
self[i-1] < value <= self[i]
right
self[i-1] <= value < self[i]
- valuearray_like
Values to insert into self.
- side{‘left’, ‘right’}, optional
If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of self).
- sorter1-D array_like, optional
Optional array of integer indices that sort array a into ascending order. They are typically the result of argsort.
- array of ints
Array of insertion points with the same shape as value.
numpy.searchsorted : Similar method from NumPy.
-
setitem
(indexer, value)¶ Set the ‘value’ inplace.
-
shift
(periods=1, fill_value=None)¶ Shift values by desired number.
Newly introduced missing values are filled with
self.dtype.na_value
.New in version 0.24.0.
- periodsint, default 1
The number of periods to shift. Negative values are allowed for shifting backwards.
- fill_valueobject, optional
The scalar value to use for newly introduced missing values. The default is
self.dtype.na_value
.New in version 0.24.0.
- ExtensionArray
Shifted.
If
self
is empty orperiods
is 0, a copy ofself
is returned.If
periods > len(self)
, then an array of size len(self) is returned, with all values filled withself.dtype.na_value
.- Return type
ExtensionArray
-
take
(indices, allow_fill=False, fill_value=None)¶ Take elements from an array.
- indicessequence of int
Indices to be taken.
- allow_fillbool, default False
How to handle negative values in indices.
False: negative values in indices indicate positional indices from the right (the default). This is similar to
numpy.take()
.True: negative values in indices indicate missing values. These values are set to fill_value. Any other other negative values raise a
ValueError
.
- fill_valueany, optional
Fill value to use for NA-indices when allow_fill is True. This may be
None
, in which case the default NA value for the type,self.dtype.na_value
, is used.For many ExtensionArrays, there will be two representations of fill_value: a user-facing “boxed” scalar, and a low-level physical NA value. fill_value should be the user-facing version, and the implementation should handle translating that to the physical version for processing the take if necessary.
ExtensionArray
- IndexError
When the indices are out of bounds for the array.
- ValueError
When indices contains negative values other than
-1
and allow_fill is True.
numpy.take : Take elements from an array along an axis. api.extensions.take : Take elements from an array.
ExtensionArray.take is called by
Series.__getitem__
,.loc
,iloc
, when indices is a sequence of values. Additionally, it’s called bySeries.reindex()
, or any other method that causes realignment, with a fill_value.Here’s an example implementation, which relies on casting the extension array to object dtype. This uses the helper method
pandas.api.extensions.take()
.def take(self, indices, allow_fill=False, fill_value=None): from pandas.core.algorithms import take # If the ExtensionArray is backed by an ndarray, then # just pass that here instead of coercing to object. data = self.astype(object) if allow_fill and fill_value is None: fill_value = self.dtype.na_value # fill value should always be translated from the scalar # type for the array, to the physical storage type for # the data, before passing to take. result = take(data, indices, fill_value=fill_value, allow_fill=allow_fill) return self._from_sequence(result, dtype=self.dtype)
-
to_numpy
(dtype=None, copy=False, na_value=<object object>)¶ Convert to a NumPy ndarray.
New in version 1.0.0.
This is similar to
numpy.asarray()
, but may provide additional control over how the conversion is done.- dtypestr or numpy.dtype, optional
The dtype to pass to
numpy.asarray()
.- copybool, default False
Whether to ensure that the returned value is a not a view on another array. Note that
copy=False
does not ensure thatto_numpy()
is no-copy. Rather,copy=True
ensure that a copy is made, even if not strictly necessary.- na_valueAny, optional
The value to use for missing values. The default value depends on dtype and the type of the array.
numpy.ndarray
- Return type
-
transpose
(*axes)¶ Return a transposed view on this array.
Because ExtensionArrays are always 1D, this is a no-op. It is included for compatibility with np.ndarray.
- Return type
ExtensionArray
-
unique
()¶ Compute the ExtensionArray of unique values.
uniques : ExtensionArray
- Return type
ExtensionArray
-
view
(dtype=None)¶ Return a view on the array.
- dtypestr, np.dtype, or ExtensionDtype, optional
Default None.
- ExtensionArray or np.ndarray
A view on the
ExtensionArray
’s data.
- Return type
~ArrayLike
-
to_temperature
(values)[source]¶ Convert values to a
TemperatureArray
.
si_unit_pandas.__init__
¶
Custom Pandas dtypes for values with SI units.
Classes:
|
|
Numpy dtype representing a temperature in degrees Celsius. |
|
|
|
|
Holder for Temperatures. |
Functions:
|
Convert values to a |
-
class
Celsius
(value)[source]¶ Bases:
UserFloat
float
subclass representing a temperature in Celsius.Convert a string or number to a floating point number, if possible.
Methods:
__abs__
()Return
abs(self)
.__add__
(other)Return
self + value
.__bool__
()True if self != 0.
__ceil__
()Finds the least Integral >= self.
complex(self) == complex(float(self), 0)
__divmod__
(other)Return
divmod(self, value)
.__eq__
(other)Return
self == other
.Return
float(self)
.Finds the greatest Integral <= self.
__floordiv__
(other)Return
self // value
.__ge__
(other)Return
self >= other
.__gt__
(other)Return
self > other
.__int__
()Return
int(self)
.__le__
(other)Return
self <= other
.__lt__
(other)Return
self < other
.__mod__
(other)Return
self % value
.__mul__
(other)Return
self * value
.__ne__
(other)Return
self != other
.__neg__
()Return
- self
.__pos__
()Return
+ self
.__pow__
(other[, mod])Return
pow(self, value, mod)
.__radd__
(other)Return
value + self
.__rdivmod__
(other)Return
divmod(value, self)
.__repr__
()Return a string representation of the temperature.
__rfloordiv__
(other)Return
value // self
.__rmod__
(other)Return
value % self
.__rmul__
(other)Return
value * self
.__round__
([ndigits])Rounds self to ndigits decimal places, defaulting to 0.
__rpow__
(other[, mod])Return
pow(value, self, mod)
.__rsub__
(other)Return
value - self
.__rtruediv__
(other)Return
value / self
.__str__
()Return the temperature as a string.
__sub__
(other)Return
value - self
.__truediv__
(other)Return
self / value
.trunc(self): Truncates self to an Integral.
Conjugate is a no-op for Reals.
fromhex
(_UserFloat__s)- rtype
~_F
hex
()- rtype
- rtype
Attributes:
Real numbers have no imaginary component.
Real numbers are their real component.
-
__add__
(other)¶ Return
self + value
.- Return type
~_F
-
__ceil__
()¶ Finds the least Integral >= self.
-
__complex__
()¶ complex(self) == complex(float(self), 0)
-
__divmod__
(other)¶ Return
divmod(self, value)
.- Return type
Tuple
[~_F
,~_F
]
-
__float__
()¶ Return
float(self)
.- Return type
-
__floor__
()¶ Finds the greatest Integral <= self.
-
__floordiv__
(other)¶ Return
self // value
.- Return type
~_F
-
__mod__
(other)¶ Return
self % value
.- Return type
~_F
-
__mul__
(other)¶ Return
self * value
.- Return type
~_F
-
__neg__
()¶ Return
- self
.- Return type
~_F
-
__pos__
()¶ Return
+ self
.- Return type
~_F
-
__pow__
(other, mod=None)¶ Return
pow(self, value, mod)
.- Return type
~_F
-
__radd__
(other)¶ Return
value + self
.- Return type
~_F
-
__rdivmod__
(other)¶ Return
divmod(value, self)
.- Return type
Tuple
[~_F
,~_F
]
-
__rfloordiv__
(other)¶ Return
value // self
.- Return type
~_F
-
__rmod__
(other)¶ Return
value % self
.- Return type
~_F
-
__rmul__
(other)¶ Return
value * self
.- Return type
~_F
-
__round__
(ndigits=None)¶ Rounds self to ndigits decimal places, defaulting to 0.
If ndigits is omitted or None, returns an Integral, otherwise returns a Real. Rounds half toward even.
-
__rpow__
(other, mod=None)¶ Return
pow(value, self, mod)
.- Return type
~_F
-
__rsub__
(other)¶ Return
value - self
.- Return type
~_F
-
__rtruediv__
(other)¶ Return
value / self
.- Return type
~_F
-
__slots__
= ()¶
-
__sub__
(other)¶ Return
value - self
.- Return type
~_F
-
__truediv__
(other)¶ Return
self / value
.- Return type
~_F
-
__trunc__
()¶ trunc(self): Truncates self to an Integral.
- Returns an Integral i such that:
i>0 iff self>0;
abs(i) <= abs(self);
for any Integral j satisfying the first two conditions, abs(i) >= abs(j) [i.e. i has “maximal” abs among those].
i.e. “truncate towards 0”.
- Return type
-
_abc_impl
= <_abc_data object>¶
-
conjugate
()¶ Conjugate is a no-op for Reals.
-
classmethod
fromhex
(_UserFloat__s)¶ - Return type
~_F
-
property
imag
¶ Real numbers have no imaginary component.
-
property
real
¶ Real numbers are their real component.
-
class
CelsiusType
[source]¶ Bases:
ExtensionDtype
Numpy dtype representing a temperature in degrees Celsius.
Methods:
__eq__
(other)Check whether ‘other’ is equal to self.
__ne__
(other)Return self!=value.
__str__
()Return str(self).
_get_common_dtype
(dtypes)Return the common dtype, if one exists.
Return the array type associated with this dtype.
construct_from_string
(string)Construct a
CelsiusType
from a string.is_dtype
(dtype)Check if we match ‘dtype’.
Attributes:
Whether this dtype should be considered boolean.
Whether columns with this dtype should be considered numeric.
Default NA value to use for this type.
Ordered list of field names, or None if there are no fields.
Classes:
alias of
builtins.float
alias of
TemperatureBase
-
__eq__
(other)¶ Check whether ‘other’ is equal to self.
By default, ‘other’ is considered equal if either
it’s a string matching ‘self.name’.
it’s an instance of this type and all of the attributes in
self._metadata
are equal between self and other.
other : Any
bool
- Return type
-
_get_common_dtype
(dtypes)¶ Return the common dtype, if one exists.
Used in find_common_type implementation. This is for example used to determine the resulting dtype in a concat operation.
If no common dtype exists, return None (which gives the other dtypes the chance to determine a common dtype). If all dtypes in the list return None, then the common dtype will be “object” dtype (this means it is never needed to return “object” dtype from this method itself).
- dtypeslist of dtypes
The dtypes for which to determine a common dtype. This is a list of np.dtype or ExtensionDtype instances.
Common dtype (np.dtype or ExtensionDtype) or None
-
property
_is_boolean
¶ Whether this dtype should be considered boolean.
By default, ExtensionDtypes are assumed to be non-numeric. Setting this to True will affect the behavior of several places, e.g.
is_bool
boolean indexing
- Return type
-
property
_is_numeric
¶ Whether columns with this dtype should be considered numeric.
By default ExtensionDtypes are assumed to be non-numeric. They’ll be excluded from operations that exclude non-numeric columns, like (groupby) reductions, plotting, etc.
- Return type
-
_record_type
¶ alias of
builtins.float
-
classmethod
construct_array_type
()[source]¶ Return the array type associated with this dtype.
type
- Return type
Type
[TemperatureArray
]
-
classmethod
construct_from_string
(string)[source]¶ Construct a
CelsiusType
from a string.- Parameters
string
-
classmethod
is_dtype
(dtype)¶ Check if we match ‘dtype’.
- dtypeobject
The object to check.
bool
The default implementation is True if
cls.construct_from_string(dtype)
is an instance ofcls
.dtype
is an object and is an instance ofcls
dtype
has adtype
attribute, and any of the above conditions is true fordtype.dtype
.
- Return type
-
property
na_value
¶ Default NA value to use for this type.
This is used in e.g. ExtensionArray.take. This should be the user-facing “boxed” version of the NA value, not the physical NA value for storage. e.g. for JSONArray, this is an empty dictionary.
- Return type
-
property
names
¶ Ordered list of field names, or None if there are no fields.
This is for compatibility with NumPy arrays, and may be removed in the future.
-
type
¶ alias of
TemperatureBase
-
-
class
Fahrenheit
(value=0.0)[source]¶ Bases:
UserFloat
float
subclass representing a temperature in Fahrenheit.Convert a string or number to a floating point number, if possible.
Methods:
__abs__
()Return
abs(self)
.__add__
(other)Return
self + value
.__bool__
()True if self != 0.
__ceil__
()Finds the least Integral >= self.
complex(self) == complex(float(self), 0)
__divmod__
(other)Return
divmod(self, value)
.__eq__
(other)Return
self == other
.Return
float(self)
.Finds the greatest Integral <= self.
__floordiv__
(other)Return
self // value
.__ge__
(other)Return
self >= other
.__gt__
(other)Return
self > other
.__int__
()Return
int(self)
.__le__
(other)Return
self <= other
.__lt__
(other)Return
self < other
.__mod__
(other)Return
self % value
.__mul__
(other)Return
self * value
.__ne__
(other)Return
self != other
.__neg__
()Return
- self
.__pos__
()Return
+ self
.__pow__
(other[, mod])Return
pow(self, value, mod)
.__radd__
(other)Return
value + self
.__rdivmod__
(other)Return
divmod(value, self)
.__repr__
()Return a string representation of the temperature.
__rfloordiv__
(other)Return
value // self
.__rmod__
(other)Return
value % self
.__rmul__
(other)Return
value * self
.__round__
([ndigits])Rounds self to ndigits decimal places, defaulting to 0.
__rpow__
(other[, mod])Return
pow(value, self, mod)
.__rsub__
(other)Return
value - self
.__rtruediv__
(other)Return
value / self
.__str__
()Return the temperature as a string.
__sub__
(other)Return
value - self
.__truediv__
(other)Return
self / value
.trunc(self): Truncates self to an Integral.
Conjugate is a no-op for Reals.
fromhex
(_UserFloat__s)- rtype
~_F
hex
()- rtype
- rtype
Attributes:
Real numbers have no imaginary component.
Real numbers are their real component.
-
__add__
(other)¶ Return
self + value
.- Return type
~_F
-
__ceil__
()¶ Finds the least Integral >= self.
-
__complex__
()¶ complex(self) == complex(float(self), 0)
-
__divmod__
(other)¶ Return
divmod(self, value)
.- Return type
Tuple
[~_F
,~_F
]
-
__float__
()¶ Return
float(self)
.- Return type
-
__floor__
()¶ Finds the greatest Integral <= self.
-
__floordiv__
(other)¶ Return
self // value
.- Return type
~_F
-
__mod__
(other)¶ Return
self % value
.- Return type
~_F
-
__mul__
(other)¶ Return
self * value
.- Return type
~_F
-
__neg__
()¶ Return
- self
.- Return type
~_F
-
__pos__
()¶ Return
+ self
.- Return type
~_F
-
__pow__
(other, mod=None)¶ Return
pow(self, value, mod)
.- Return type
~_F
-
__radd__
(other)¶ Return
value + self
.- Return type
~_F
-
__rdivmod__
(other)¶ Return
divmod(value, self)
.- Return type
Tuple
[~_F
,~_F
]
-
__rfloordiv__
(other)¶ Return
value // self
.- Return type
~_F
-
__rmod__
(other)¶ Return
value % self
.- Return type
~_F
-
__rmul__
(other)¶ Return
value * self
.- Return type
~_F
-
__round__
(ndigits=None)¶ Rounds self to ndigits decimal places, defaulting to 0.
If ndigits is omitted or None, returns an Integral, otherwise returns a Real. Rounds half toward even.
-
__rpow__
(other, mod=None)¶ Return
pow(value, self, mod)
.- Return type
~_F
-
__rsub__
(other)¶ Return
value - self
.- Return type
~_F
-
__rtruediv__
(other)¶ Return
value / self
.- Return type
~_F
-
__slots__
= ()¶
-
__sub__
(other)¶ Return
value - self
.- Return type
~_F
-
__truediv__
(other)¶ Return
self / value
.- Return type
~_F
-
__trunc__
()¶ trunc(self): Truncates self to an Integral.
- Returns an Integral i such that:
i>0 iff self>0;
abs(i) <= abs(self);
for any Integral j satisfying the first two conditions, abs(i) >= abs(j) [i.e. i has “maximal” abs among those].
i.e. “truncate towards 0”.
- Return type
-
_abc_impl
= <_abc_data object>¶
-
conjugate
()¶ Conjugate is a no-op for Reals.
-
classmethod
fromhex
(_UserFloat__s)¶ - Return type
~_F
-
property
imag
¶ Real numbers have no imaginary component.
-
property
real
¶ Real numbers are their real component.
-
class
TemperatureArray
(data, dtype=None, copy=False)[source]¶ Bases:
BaseArray
Holder for Temperatures.
TemperatureArray is a container for Temperatures. It satisfies pandas’ extension array interface, and so can be stored inside
pandas.Series
andpandas.DataFrame
.Attributes:
- rtype
ExtensionArray
The dtype for this extension array,
CelsiusType
.The missing value.
The number of bytes needed to store this object in memory.
Return a tuple of the array dimensions.
The number of elements in the array.
Methods:
__abs__
()__add__
(other)__and__
(other)__contains__
(item)Return for item in self.
__delitem__
(where)__divmod__
(other)__eq__
(other)Return for self == other (element-wise equality).
__floordiv__
(other)__ge__
(other)Return self>=value.
__getitem__
(item)Select a subset of self.
__gt__
(other)Return self>value.
__iadd__
(other)__iand__
(other)__ifloordiv__
(other)__ilshift__
(other)__imatmul__
(other)__imod__
(other)__imul__
(other)__ior__
(other)__ipow__
(other)__irshift__
(other)__isub__
(other)__iter__
()Iterate over elements of the array.
__itruediv__
(other)__ixor__
(other)__le__
(other)Return self<=value.
__len__
()Returns the length of this array.
__lshift__
(other)__lt__
(other)Return self<value.
__matmul__
(other)__mod__
(other)__mul__
(other)__ne__
(other)Return for self != other (element-wise in-equality).
__neg__
()__or__
(other)__pos__
()__pow__
(other)__radd__
(other)__rand__
(other)__rdivmod__
(other)__repr__
()Return repr(self).
__rfloordiv__
(other)__rlshift__
(other)__rmatmul__
(other)__rmod__
(other)__rmul__
(other)__ror__
(other)__rpow__
(other)__rrshift__
(other)__rshift__
(other)__rsub__
(other)__rtruediv__
(other)__rxor__
(other)__setitem__
(key, value)Set one or more values inplace.
__sub__
(other)__truediv__
(other)__xor__
(other)_concat_same_type
(to_concat)Concatenate multiple arrays.
_formatter
([boxed])Formatting function for scalar values.
_from_factorized
(values, original)Reconstruct an ExtensionArray after factorization.
_from_ndarray
(data[, copy])Zero-copy construction of a BaseArray from an ndarray.
_from_sequence
(scalars[, dtype, copy])Construct a new ExtensionArray from a sequence of scalars.
_from_sequence_of_strings
(strings, *[, …])Construct a new ExtensionArray from a sequence of strings.
_isstringslice
(where)_reduce
(name, *[, skipna])Return a scalar result of performing the reduction operation.
Return values for sorting.
Return an array and missing value suitable for factorization.
append
(value)Append a value to this TemperatureArray.
argmax
()Return the index of maximum value.
argmin
()Return the index of minimum value.
argsort
([ascending, kind])Return the indices that would sort this array.
astype
(dtype[, copy])Returns the array with its values as the given dtype.
copy
([deep])Return a copy of the array.
dropna
()Return ExtensionArray without NA values.
equals
(other)Return if another array is equivalent to this array.
factorize
([na_sentinel])Encode the extension array as an enumerated type.
fillna
([value, method, limit])Fill NA/NaN values using the specified method.
isin
(other)Check whether elements of self are in other.
isna
()Indicator for whether each element is missing.
ravel
([order])Return a flattened view on this array.
repeat
(repeats[, axis])Repeat elements of a ExtensionArray.
searchsorted
(value[, side, sorter])Find indices where elements should be inserted to maintain order.
setitem
(indexer, value)Set the ‘value’ inplace.
shift
([periods, fill_value])Shift values by desired number.
take
(indices[, allow_fill, fill_value])Take elements from an array.
to_numpy
([dtype, copy, na_value])Convert to a NumPy ndarray.
tolist
()Convert the array to a Python list.
transpose
(*axes)Return a transposed view on this array.
unique
()Compute the ExtensionArray of unique values.
view
([dtype])Return a view on the array.
-
property
T
¶ - Return type
ExtensionArray
-
__abs__
()¶
-
__add__
(other)¶
-
__and__
(other)¶
-
__delitem__
(where)¶
-
__divmod__
(other)¶
-
__eq__
(other)¶ Return for self == other (element-wise equality).
-
__floordiv__
(other)¶
-
__ge__
(other)¶ Return self>=value.
-
__getitem__
(item)[source]¶ Select a subset of self.
- Parameters
item (
Union
[int
,slice
,ndarray
]) –int: The position in ‘self’ to get.
slice: A slice object, where ‘start’, ‘stop’, and ‘step’ are integers or None.
ndarray: A 1-d boolean NumPy ndarray the same length as ‘self’
- Return type
scalar or ExtensionArray
Note
For scalar
item
, return a scalar value suitable for the array’s type. This should be an instance ofself.dtype.type
.For slice
key
, return an instance ofExtensionArray
, even if the slice is length 0 or 1.For a boolean mask, return an instance of
ExtensionArray
, filtered to the values whereitem
is True.
-
__gt__
(other)¶ Return self>value.
-
__iadd__
(other)¶
-
__iand__
(other)¶
-
__ifloordiv__
(other)¶
-
__ilshift__
(other)¶
-
__imatmul__
(other)¶
-
__imod__
(other)¶
-
__imul__
(other)¶
-
__invert__
()¶
-
__ior__
(other)¶
-
__ipow__
(other)¶
-
__irshift__
(other)¶
-
__isub__
(other)¶
-
__iter__
()¶ Iterate over elements of the array.
-
__itruediv__
(other)¶
-
__ixor__
(other)¶
-
__le__
(other)¶ Return self<=value.
-
__lshift__
(other)¶
-
__lt__
(other)¶ Return self<value.
-
__matmul__
(other)¶
-
__mod__
(other)¶
-
__mul__
(other)¶
-
__ne__
(other)¶ Return for self != other (element-wise in-equality).
-
__neg__
()¶
-
__or__
(other)¶
-
__pos__
()¶
-
__pow__
(other)¶
-
__radd__
(other)¶
-
__rand__
(other)¶
-
__rdivmod__
(other)¶
-
__rfloordiv__
(other)¶
-
__rlshift__
(other)¶
-
__rmatmul__
(other)¶
-
__rmod__
(other)¶
-
__rmul__
(other)¶
-
__ror__
(other)¶
-
__rpow__
(other)¶
-
__rrshift__
(other)¶
-
__rshift__
(other)¶
-
__rsub__
(other)¶
-
__rtruediv__
(other)¶
-
__rxor__
(other)¶
-
__setitem__
(key, value)¶ Set one or more values inplace.
This method is not required to satisfy the pandas extension array interface.
- keyint, ndarray, or slice
When called from, e.g.
Series.__setitem__
,key
will be one ofscalar int
ndarray of integers.
boolean ndarray
slice object
- valueExtensionDtype.type, Sequence[ExtensionDtype.type], or object
value or values to be set of
key
.
None
-
__sub__
(other)¶
-
__truediv__
(other)¶
-
__xor__
(other)¶
-
_can_hold_na
= True¶
-
classmethod
_concat_same_type
(to_concat)¶ Concatenate multiple arrays.
- Parameters
to_concat (
Sequence
[ABCExtensionArray
]) – sequence of this type- Return type
ABCExtensionArray
-
_dtype
: Type[pandas.core.dtypes.base.ExtensionDtype] = <si_unit_pandas.temperature.CelsiusType object>¶
-
_formatter
(boxed=False)¶ Formatting function for scalar values.
This is used in the default ‘__repr__’. The returned formatting function receives instances of your scalar type.
- boxedbool, default False
An indicated for whether or not your array is being printed within a Series, DataFrame, or Index (True), or just by itself (False). This may be useful if you want scalar values to appear differently within a Series versus on its own (e.g. quoted or not).
- Callable[[Any], str]
A callable that gets instances of the scalar type and returns a string. By default,
repr()
is used whenboxed=False
andstr()
is used whenboxed=True
.
-
_formatting_values
()¶
-
classmethod
_from_factorized
(values, original)¶ Reconstruct an ExtensionArray after factorization.
- Parameters
values (
ndarray
) – An integer ndarray with the factorized values.original (
ExtensionArray
) – The original ExtensionArray that factorize was called on.
See also
pandas.pandas.api.extensions.ExtensionArray.factorize()
-
classmethod
_from_ndarray
(data, copy=False)¶ Zero-copy construction of a BaseArray from an ndarray.
-
classmethod
_from_sequence
(scalars, dtype=None, copy=False)¶ Construct a new ExtensionArray from a sequence of scalars.
- Parameters
scalars (
Iterable
) – Each element will be an instance of the scalar type for this array,cls.dtype.type
.dtype (dtype, optional) – Construct for this particular dtype. This should be a Dtype compatible with the ExtensionArray. Default
None
.copy (
bool
) – If True, copy the underlying data. DefaultFalse
.
-
classmethod
_from_sequence_of_strings
(strings, *, dtype=None, copy=False)¶ Construct a new ExtensionArray from a sequence of strings.
New in version 0.24.0.
- stringsSequence
Each element will be an instance of the scalar type for this array,
cls.dtype.type
.- dtypedtype, optional
Construct for this particular dtype. This should be a Dtype compatible with the ExtensionArray.
- copybool, default False
If True, copy the underlying data.
ExtensionArray
-
_isstringslice
(where)¶
-
property
_parser
¶
-
_reduce
(name, *, skipna=True, **kwargs)¶ Return a scalar result of performing the reduction operation.
- namestr
Name of the function, supported values are: { any, all, min, max, sum, mean, median, prod, std, var, sem, kurt, skew }.
- skipnabool, default True
If True, skip NaN values.
- **kwargs
Additional keyword arguments passed to the reduction function. Currently, ddof is the only supported kwarg.
scalar
TypeError : subclass does not define reductions
-
_typ
= 'extension'¶
-
_values_for_argsort
()¶ Return values for sorting.
- ndarray
The transformed values should maintain the ordering between values within the array.
ExtensionArray.argsort : Return the indices that would sort this array.
- Return type
-
_values_for_factorize
()¶ Return an array and missing value suitable for factorization.
values : ndarray
An array suitable for factorization. This should maintain order and be a supported dtype (Float64, Int64, UInt64, String, Object). By default, the extension array is cast to object dtype.
- na_valueobject
The value in values to consider missing. This will be treated as NA in the factorization routines, so it will be coded as na_sentinel and not included in uniques. By default,
np.nan
is used.
The values returned by this method are also used in
pandas.util.hash_pandas_object()
.
-
argmax
()¶ Return the index of maximum value.
In case of multiple occurrences of the maximum value, the index corresponding to the first occurrence is returned.
int
ExtensionArray.argmin
-
argmin
()¶ Return the index of minimum value.
In case of multiple occurrences of the minimum value, the index corresponding to the first occurrence is returned.
int
ExtensionArray.argmax
-
argsort
(ascending=True, kind='quicksort', *args, **kwargs)¶ Return the indices that would sort this array.
- Parameters
*args and **kwargs are passed through to
numpy.argsort()
.- Return type
- Returns
Array of indices that sort
self
. If NaN values are contained, NaN values are placed at the end.
See also
numpy.argsort
: Sorting implementation used internally.
-
copy
(deep=False)¶ Return a copy of the array.
-
dropna
()¶ Return ExtensionArray without NA values.
valid : ExtensionArray
-
property
dtype
¶ The dtype for this extension array,
CelsiusType
.
-
equals
(other)¶ Return if another array is equivalent to this array.
Equivalent means that both arrays have the same shape and dtype, and all values compare equal. Missing values in the same location are considered equal (in contrast with normal equality).
- otherExtensionArray
Array to compare to this Array.
- boolean
Whether the arrays are equivalent.
- Return type
-
factorize
(na_sentinel=- 1)¶ Encode the extension array as an enumerated type.
- na_sentinelint, default -1
Value to use in the codes array to indicate missing values.
- codesndarray
An integer NumPy array that’s an indexer into the original ExtensionArray.
- uniquesExtensionArray
An ExtensionArray containing the unique values of self.
Note
uniques will not contain an entry for the NA value of the ExtensionArray if there are any missing values present in self.
factorize : Top-level factorize method that dispatches here.
pandas.factorize()
offers a sort keyword as well.
-
fillna
(value=None, method=None, limit=None)¶ Fill NA/NaN values using the specified method.
- valuescalar, array-like
If a scalar value is passed it is used to fill all missing values. Alternatively, an array-like ‘value’ can be given. It’s expected that the array-like have the same length as ‘self’.
- method{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None
Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use NEXT valid observation to fill gap.
- limitint, default None
If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled.
- ExtensionArray
With NA/NaN filled.
-
isna
()¶ Indicator for whether each element is missing.
-
property
na_value
¶ The missing value.
Example:
>>> BaseArray([]).na_value numpy.nan
-
ravel
(order='C')¶ Return a flattened view on this array.
order : {None, ‘C’, ‘F’, ‘A’, ‘K’}, default ‘C’
ExtensionArray
Because ExtensionArrays are 1D-only, this is a no-op.
The “order” argument is ignored, is for compatibility with NumPy.
- Return type
ExtensionArray
-
repeat
(repeats, axis=None)¶ Repeat elements of a ExtensionArray.
Returns a new ExtensionArray where each element of the current ExtensionArray is repeated consecutively a given number of times.
- repeatsint or array of ints
The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty ExtensionArray.
- axisNone
Must be
None
. Has no effect but is accepted for compatibility with numpy.
- repeated_arrayExtensionArray
Newly created ExtensionArray with repeated elements.
Series.repeat : Equivalent function for Series. Index.repeat : Equivalent function for Index. numpy.repeat : Similar method for
numpy.ndarray
. ExtensionArray.take : Take arbitrary positions.>>> cat = pd.Categorical(['a', 'b', 'c']) >>> cat ['a', 'b', 'c'] Categories (3, object): ['a', 'b', 'c'] >>> cat.repeat(2) ['a', 'a', 'b', 'b', 'c', 'c'] Categories (3, object): ['a', 'b', 'c'] >>> cat.repeat([1, 2, 3]) ['a', 'b', 'b', 'c', 'c', 'c'] Categories (3, object): ['a', 'b', 'c']
-
searchsorted
(value, side='left', sorter=None)¶ Find indices where elements should be inserted to maintain order.
New in version 0.24.0.
Find the indices into a sorted array self (a) such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved.
Assuming that self is sorted:
side
returned index i satisfies
left
self[i-1] < value <= self[i]
right
self[i-1] <= value < self[i]
- valuearray_like
Values to insert into self.
- side{‘left’, ‘right’}, optional
If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of self).
- sorter1-D array_like, optional
Optional array of integer indices that sort array a into ascending order. They are typically the result of argsort.
- array of ints
Array of insertion points with the same shape as value.
numpy.searchsorted : Similar method from NumPy.
-
setitem
(indexer, value)¶ Set the ‘value’ inplace.
-
shift
(periods=1, fill_value=None)¶ Shift values by desired number.
Newly introduced missing values are filled with
self.dtype.na_value
.New in version 0.24.0.
- periodsint, default 1
The number of periods to shift. Negative values are allowed for shifting backwards.
- fill_valueobject, optional
The scalar value to use for newly introduced missing values. The default is
self.dtype.na_value
.New in version 0.24.0.
- ExtensionArray
Shifted.
If
self
is empty orperiods
is 0, a copy ofself
is returned.If
periods > len(self)
, then an array of size len(self) is returned, with all values filled withself.dtype.na_value
.- Return type
ExtensionArray
-
take
(indices, allow_fill=False, fill_value=None)¶ Take elements from an array.
- indicessequence of int
Indices to be taken.
- allow_fillbool, default False
How to handle negative values in indices.
False: negative values in indices indicate positional indices from the right (the default). This is similar to
numpy.take()
.True: negative values in indices indicate missing values. These values are set to fill_value. Any other other negative values raise a
ValueError
.
- fill_valueany, optional
Fill value to use for NA-indices when allow_fill is True. This may be
None
, in which case the default NA value for the type,self.dtype.na_value
, is used.For many ExtensionArrays, there will be two representations of fill_value: a user-facing “boxed” scalar, and a low-level physical NA value. fill_value should be the user-facing version, and the implementation should handle translating that to the physical version for processing the take if necessary.
ExtensionArray
- IndexError
When the indices are out of bounds for the array.
- ValueError
When indices contains negative values other than
-1
and allow_fill is True.
numpy.take : Take elements from an array along an axis. api.extensions.take : Take elements from an array.
ExtensionArray.take is called by
Series.__getitem__
,.loc
,iloc
, when indices is a sequence of values. Additionally, it’s called bySeries.reindex()
, or any other method that causes realignment, with a fill_value.Here’s an example implementation, which relies on casting the extension array to object dtype. This uses the helper method
pandas.api.extensions.take()
.def take(self, indices, allow_fill=False, fill_value=None): from pandas.core.algorithms import take # If the ExtensionArray is backed by an ndarray, then # just pass that here instead of coercing to object. data = self.astype(object) if allow_fill and fill_value is None: fill_value = self.dtype.na_value # fill value should always be translated from the scalar # type for the array, to the physical storage type for # the data, before passing to take. result = take(data, indices, fill_value=fill_value, allow_fill=allow_fill) return self._from_sequence(result, dtype=self.dtype)
-
to_numpy
(dtype=None, copy=False, na_value=<object object>)¶ Convert to a NumPy ndarray.
New in version 1.0.0.
This is similar to
numpy.asarray()
, but may provide additional control over how the conversion is done.- dtypestr or numpy.dtype, optional
The dtype to pass to
numpy.asarray()
.- copybool, default False
Whether to ensure that the returned value is a not a view on another array. Note that
copy=False
does not ensure thatto_numpy()
is no-copy. Rather,copy=True
ensure that a copy is made, even if not strictly necessary.- na_valueAny, optional
The value to use for missing values. The default value depends on dtype and the type of the array.
numpy.ndarray
- Return type
-
transpose
(*axes)¶ Return a transposed view on this array.
Because ExtensionArrays are always 1D, this is a no-op. It is included for compatibility with np.ndarray.
- Return type
ExtensionArray
-
unique
()¶ Compute the ExtensionArray of unique values.
uniques : ExtensionArray
- Return type
ExtensionArray
-
view
(dtype=None)¶ Return a view on the array.
- dtypestr, np.dtype, or ExtensionDtype, optional
Default None.
- ExtensionArray or np.ndarray
A view on the
ExtensionArray
’s data.
- Return type
~ArrayLike
si_unit_pandas.base
¶
Base functionality.
Classes:
Mixin for pandas extension backed by a numpy array. |
-
class
NumPyBackedExtensionArrayMixin
[source]¶ Bases:
ExtensionArray
Mixin for pandas extension backed by a numpy array.
Attributes:
- rtype
ExtensionArray
The dtype for this extension array,
CelsiusType
.The number of bytes needed to store this object in memory.
Extension Arrays are only allowed to be 1-dimensional.
Return a tuple of the array dimensions.
The number of elements in the array.
Methods:
__contains__
(item)Return for item in self.
__eq__
(other)Return for self == other (element-wise equality).
__getitem__
(item)Select a subset of self.
__iter__
()Iterate over elements of the array.
__len__
()Returns the length of this array.
__ne__
(other)Return for self != other (element-wise in-equality).
__repr__
()Return repr(self).
__setitem__
(key, value)Set one or more values inplace.
_concat_same_type
(to_concat)Concatenate multiple arrays.
_formatter
([boxed])Formatting function for scalar values.
_from_factorized
(values, original)Reconstruct an ExtensionArray after factorization.
_from_sequence
(scalars[, dtype, copy])Construct a new ExtensionArray from a sequence of scalars.
_from_sequence_of_strings
(strings, *[, …])Construct a new ExtensionArray from a sequence of strings.
_reduce
(name, *[, skipna])Return a scalar result of performing the reduction operation.
Return values for sorting.
Return an array and missing value suitable for factorization.
argmax
()Return the index of maximum value.
argmin
()Return the index of minimum value.
argsort
([ascending, kind])Return the indices that would sort this array.
astype
(dtype[, copy])Cast to a NumPy array with ‘dtype’.
copy
([deep])Return a copy of the array.
dropna
()Return ExtensionArray without NA values.
equals
(other)Return if another array is equivalent to this array.
factorize
([na_sentinel])Encode the extension array as an enumerated type.
fillna
([value, method, limit])Fill NA/NaN values using the specified method.
isna
()A 1-D array indicating if each value is missing.
ravel
([order])Return a flattened view on this array.
repeat
(repeats[, axis])Repeat elements of a ExtensionArray.
searchsorted
(value[, side, sorter])Find indices where elements should be inserted to maintain order.
setitem
(indexer, value)Set the ‘value’ inplace.
shift
([periods, fill_value])Shift values by desired number.
take
(indices, *[, allow_fill, fill_value])Take elements from an array.
to_numpy
([dtype, copy, na_value])Convert to a NumPy ndarray.
tolist
()Convert the array to a Python list.
transpose
(*axes)Return a transposed view on this array.
unique
()Compute the ExtensionArray of unique values.
view
([dtype])Return a view on the array.
-
property
T
¶ - Return type
ExtensionArray
-
__eq__
(other)¶ Return for self == other (element-wise equality).
- Return type
~ArrayLike
-
__getitem__
(item)¶ Select a subset of self.
- itemint, slice, or ndarray
int: The position in ‘self’ to get.
slice: A slice object, where ‘start’, ‘stop’, and ‘step’ are integers or None
ndarray: A 1-d boolean NumPy ndarray the same length as ‘self’
item : scalar or ExtensionArray
For scalar
item
, return a scalar value suitable for the array’s type. This should be an instance ofself.dtype.type
.For slice
key
, return an instance ofExtensionArray
, even if the slice is length 0 or 1.For a boolean mask, return an instance of
ExtensionArray
, filtered to the values whereitem
is True.
-
__iter__
()¶ Iterate over elements of the array.
-
__ne__
(other)¶ Return for self != other (element-wise in-equality).
- Return type
~ArrayLike
-
__setitem__
(key, value)¶ Set one or more values inplace.
This method is not required to satisfy the pandas extension array interface.
- keyint, ndarray, or slice
When called from, e.g.
Series.__setitem__
,key
will be one ofscalar int
ndarray of integers.
boolean ndarray
slice object
- valueExtensionDtype.type, Sequence[ExtensionDtype.type], or object
value or values to be set of
key
.
None
-
_can_hold_na
= True¶
-
classmethod
_concat_same_type
(to_concat)[source]¶ Concatenate multiple arrays.
- Parameters
to_concat (
Sequence
[ABCExtensionArray
]) – sequence of this type- Return type
ABCExtensionArray
-
_formatter
(boxed=False)¶ Formatting function for scalar values.
This is used in the default ‘__repr__’. The returned formatting function receives instances of your scalar type.
- boxedbool, default False
An indicated for whether or not your array is being printed within a Series, DataFrame, or Index (True), or just by itself (False). This may be useful if you want scalar values to appear differently within a Series versus on its own (e.g. quoted or not).
- Callable[[Any], str]
A callable that gets instances of the scalar type and returns a string. By default,
repr()
is used whenboxed=False
andstr()
is used whenboxed=True
.
-
classmethod
_from_factorized
(values, original)[source]¶ Reconstruct an ExtensionArray after factorization.
- Parameters
values (
ndarray
) – An integer ndarray with the factorized values.original (
ExtensionArray
) – The original ExtensionArray that factorize was called on.
See also
pandas.pandas.api.extensions.ExtensionArray.factorize()
-
classmethod
_from_sequence
(scalars, dtype=None, copy=False)[source]¶ Construct a new ExtensionArray from a sequence of scalars.
- Parameters
scalars (
Iterable
) – Each element will be an instance of the scalar type for this array,cls.dtype.type
.dtype (dtype, optional) – Construct for this particular dtype. This should be a Dtype compatible with the ExtensionArray. Default
None
.copy (
bool
) – If True, copy the underlying data. DefaultFalse
.
-
classmethod
_from_sequence_of_strings
(strings, *, dtype=None, copy=False)¶ Construct a new ExtensionArray from a sequence of strings.
New in version 0.24.0.
- stringsSequence
Each element will be an instance of the scalar type for this array,
cls.dtype.type
.- dtypedtype, optional
Construct for this particular dtype. This should be a Dtype compatible with the ExtensionArray.
- copybool, default False
If True, copy the underlying data.
ExtensionArray
-
_reduce
(name, *, skipna=True, **kwargs)¶ Return a scalar result of performing the reduction operation.
- namestr
Name of the function, supported values are: { any, all, min, max, sum, mean, median, prod, std, var, sem, kurt, skew }.
- skipnabool, default True
If True, skip NaN values.
- **kwargs
Additional keyword arguments passed to the reduction function. Currently, ddof is the only supported kwarg.
scalar
TypeError : subclass does not define reductions
-
_typ
= 'extension'¶
-
_values_for_argsort
()¶ Return values for sorting.
- ndarray
The transformed values should maintain the ordering between values within the array.
ExtensionArray.argsort : Return the indices that would sort this array.
- Return type
-
_values_for_factorize
()¶ Return an array and missing value suitable for factorization.
values : ndarray
An array suitable for factorization. This should maintain order and be a supported dtype (Float64, Int64, UInt64, String, Object). By default, the extension array is cast to object dtype.
- na_valueobject
The value in values to consider missing. This will be treated as NA in the factorization routines, so it will be coded as na_sentinel and not included in uniques. By default,
np.nan
is used.
The values returned by this method are also used in
pandas.util.hash_pandas_object()
.
-
argmax
()¶ Return the index of maximum value.
In case of multiple occurrences of the maximum value, the index corresponding to the first occurrence is returned.
int
ExtensionArray.argmin
-
argmin
()¶ Return the index of minimum value.
In case of multiple occurrences of the minimum value, the index corresponding to the first occurrence is returned.
int
ExtensionArray.argmax
-
argsort
(ascending=True, kind='quicksort', *args, **kwargs)[source]¶ Return the indices that would sort this array.
- Parameters
*args and **kwargs are passed through to
numpy.argsort()
.- Return type
- Returns
Array of indices that sort
self
. If NaN values are contained, NaN values are placed at the end.
See also
numpy.argsort
: Sorting implementation used internally.
-
astype
(dtype, copy=True)¶ Cast to a NumPy array with ‘dtype’.
- dtypestr or dtype
Typecode or data-type to which the array is cast.
- copybool, default True
Whether to copy the data, even if not necessary. If False, a copy is made only if the old dtype does not match the new dtype.
- arrayndarray
NumPy ndarray with ‘dtype’ for its dtype.
-
dropna
()¶ Return ExtensionArray without NA values.
valid : ExtensionArray
-
property
dtype
¶ The dtype for this extension array,
CelsiusType
.
-
equals
(other)¶ Return if another array is equivalent to this array.
Equivalent means that both arrays have the same shape and dtype, and all values compare equal. Missing values in the same location are considered equal (in contrast with normal equality).
- otherExtensionArray
Array to compare to this Array.
- boolean
Whether the arrays are equivalent.
- Return type
-
factorize
(na_sentinel=- 1)¶ Encode the extension array as an enumerated type.
- na_sentinelint, default -1
Value to use in the codes array to indicate missing values.
- codesndarray
An integer NumPy array that’s an indexer into the original ExtensionArray.
- uniquesExtensionArray
An ExtensionArray containing the unique values of self.
Note
uniques will not contain an entry for the NA value of the ExtensionArray if there are any missing values present in self.
factorize : Top-level factorize method that dispatches here.
pandas.factorize()
offers a sort keyword as well.
-
fillna
(value=None, method=None, limit=None)¶ Fill NA/NaN values using the specified method.
- valuescalar, array-like
If a scalar value is passed it is used to fill all missing values. Alternatively, an array-like ‘value’ can be given. It’s expected that the array-like have the same length as ‘self’.
- method{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None
Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use NEXT valid observation to fill gap.
- limitint, default None
If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled.
- ExtensionArray
With NA/NaN filled.
-
isna
()¶ A 1-D array indicating if each value is missing.
- na_valuesUnion[np.ndarray, ExtensionArray]
In most cases, this should return a NumPy ndarray. For exceptional cases like
SparseArray
, where returning an ndarray would be expensive, an ExtensionArray may be returned.
If returning an ExtensionArray, then
na_values._is_boolean
should be Truena_values should implement
ExtensionArray._reduce()
na_values.any
andna_values.all
should be implemented
- Return type
~ArrayLike
-
ravel
(order='C')¶ Return a flattened view on this array.
order : {None, ‘C’, ‘F’, ‘A’, ‘K’}, default ‘C’
ExtensionArray
Because ExtensionArrays are 1D-only, this is a no-op.
The “order” argument is ignored, is for compatibility with NumPy.
- Return type
ExtensionArray
-
repeat
(repeats, axis=None)¶ Repeat elements of a ExtensionArray.
Returns a new ExtensionArray where each element of the current ExtensionArray is repeated consecutively a given number of times.
- repeatsint or array of ints
The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty ExtensionArray.
- axisNone
Must be
None
. Has no effect but is accepted for compatibility with numpy.
- repeated_arrayExtensionArray
Newly created ExtensionArray with repeated elements.
Series.repeat : Equivalent function for Series. Index.repeat : Equivalent function for Index. numpy.repeat : Similar method for
numpy.ndarray
. ExtensionArray.take : Take arbitrary positions.>>> cat = pd.Categorical(['a', 'b', 'c']) >>> cat ['a', 'b', 'c'] Categories (3, object): ['a', 'b', 'c'] >>> cat.repeat(2) ['a', 'a', 'b', 'b', 'c', 'c'] Categories (3, object): ['a', 'b', 'c'] >>> cat.repeat([1, 2, 3]) ['a', 'b', 'b', 'c', 'c', 'c'] Categories (3, object): ['a', 'b', 'c']
-
searchsorted
(value, side='left', sorter=None)¶ Find indices where elements should be inserted to maintain order.
New in version 0.24.0.
Find the indices into a sorted array self (a) such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved.
Assuming that self is sorted:
side
returned index i satisfies
left
self[i-1] < value <= self[i]
right
self[i-1] <= value < self[i]
- valuearray_like
Values to insert into self.
- side{‘left’, ‘right’}, optional
If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of self).
- sorter1-D array_like, optional
Optional array of integer indices that sort array a into ascending order. They are typically the result of argsort.
- array of ints
Array of insertion points with the same shape as value.
numpy.searchsorted : Similar method from NumPy.
-
shift
(periods=1, fill_value=None)¶ Shift values by desired number.
Newly introduced missing values are filled with
self.dtype.na_value
.New in version 0.24.0.
- periodsint, default 1
The number of periods to shift. Negative values are allowed for shifting backwards.
- fill_valueobject, optional
The scalar value to use for newly introduced missing values. The default is
self.dtype.na_value
.New in version 0.24.0.
- ExtensionArray
Shifted.
If
self
is empty orperiods
is 0, a copy ofself
is returned.If
periods > len(self)
, then an array of size len(self) is returned, with all values filled withself.dtype.na_value
.- Return type
ExtensionArray
-
take
(indices, *, allow_fill=False, fill_value=None)¶ Take elements from an array.
- indicessequence of int
Indices to be taken.
- allow_fillbool, default False
How to handle negative values in indices.
False: negative values in indices indicate positional indices from the right (the default). This is similar to
numpy.take()
.True: negative values in indices indicate missing values. These values are set to fill_value. Any other other negative values raise a
ValueError
.
- fill_valueany, optional
Fill value to use for NA-indices when allow_fill is True. This may be
None
, in which case the default NA value for the type,self.dtype.na_value
, is used.For many ExtensionArrays, there will be two representations of fill_value: a user-facing “boxed” scalar, and a low-level physical NA value. fill_value should be the user-facing version, and the implementation should handle translating that to the physical version for processing the take if necessary.
ExtensionArray
- IndexError
When the indices are out of bounds for the array.
- ValueError
When indices contains negative values other than
-1
and allow_fill is True.
numpy.take : Take elements from an array along an axis. api.extensions.take : Take elements from an array.
ExtensionArray.take is called by
Series.__getitem__
,.loc
,iloc
, when indices is a sequence of values. Additionally, it’s called bySeries.reindex()
, or any other method that causes realignment, with a fill_value.Here’s an example implementation, which relies on casting the extension array to object dtype. This uses the helper method
pandas.api.extensions.take()
.def take(self, indices, allow_fill=False, fill_value=None): from pandas.core.algorithms import take # If the ExtensionArray is backed by an ndarray, then # just pass that here instead of coercing to object. data = self.astype(object) if allow_fill and fill_value is None: fill_value = self.dtype.na_value # fill value should always be translated from the scalar # type for the array, to the physical storage type for # the data, before passing to take. result = take(data, indices, fill_value=fill_value, allow_fill=allow_fill) return self._from_sequence(result, dtype=self.dtype)
- Return type
ExtensionArray
-
to_numpy
(dtype=None, copy=False, na_value=<object object>)¶ Convert to a NumPy ndarray.
New in version 1.0.0.
This is similar to
numpy.asarray()
, but may provide additional control over how the conversion is done.- dtypestr or numpy.dtype, optional
The dtype to pass to
numpy.asarray()
.- copybool, default False
Whether to ensure that the returned value is a not a view on another array. Note that
copy=False
does not ensure thatto_numpy()
is no-copy. Rather,copy=True
ensure that a copy is made, even if not strictly necessary.- na_valueAny, optional
The value to use for missing values. The default value depends on dtype and the type of the array.
numpy.ndarray
- Return type
-
transpose
(*axes)¶ Return a transposed view on this array.
Because ExtensionArrays are always 1D, this is a no-op. It is included for compatibility with np.ndarray.
- Return type
ExtensionArray
-
unique
()[source]¶ Compute the ExtensionArray of unique values.
uniques : ExtensionArray
- Return type
ExtensionArray
-
view
(dtype=None)¶ Return a view on the array.
- dtypestr, np.dtype, or ExtensionDtype, optional
Default None.
- ExtensionArray or np.ndarray
A view on the
ExtensionArray
’s data.
- Return type
~ArrayLike