ladybug_pandas.extension_types.arraytype module¶
- class ladybug_pandas.extension_types.arraytype.LadybugArrayType(values, dtype=None, copy=False)[source]¶
Bases:
ExtensionArray,ExtensionScalarOpsMixin- argmax(skipna: bool = True) int¶
Return the index of maximum value.
In case of multiple occurrences of the maximum value, the index corresponding to the first occurrence is returned.
- Parameters:
skipna (bool, default True) –
- Return type:
int
See also
ExtensionArray.argmin
- argmin(skipna: bool = True) int¶
Return the index of minimum value.
In case of multiple occurrences of the minimum value, the index corresponding to the first occurrence is returned.
- Parameters:
skipna (bool, default True) –
- Return type:
int
See also
ExtensionArray.argmax
- argsort(ascending: bool = True, kind: str = 'quicksort', na_position: str = 'last', *args, **kwargs) ndarray¶
Return the indices that would sort this array.
- Parameters:
ascending (bool, default True) – Whether the indices should result in an ascending or descending sort.
kind ({'quicksort', 'mergesort', 'heapsort', 'stable'}, optional) – Sorting algorithm.
*args – Passed through to
numpy.argsort().**kwargs – Passed through to
numpy.argsort().
- Returns:
Array of indices that sort
self. If NaN values are contained, NaN values are placed at the end.- Return type:
np.ndarray[np.intp]
See also
numpy.argsortSorting implementation used internally.
- astype(dtype, copy=True)[source]¶
Cast to a NumPy array with ‘dtype’.
- Parameters:
dtype (str or dtype) – Typecode or data-type to which the array is cast.
copy (bool, 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.
- Returns:
array – NumPy ndarray with ‘dtype’ for its dtype.
- Return type:
ndarray
- convert_to_unit(unit: str)[source]¶
Convert the Data Collection to the input unit
- Parameters:
type (unit {str} -- A unit string that exists for the data) –
- delete(loc) ExtensionArrayT¶
- dropna()¶
Return ExtensionArray without NA values.
- Returns:
valid
- Return type:
ExtensionArray
- equals(other: object) bool¶
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).
- Parameters:
other (ExtensionArray) – Array to compare to this Array.
- Returns:
Whether the arrays are equivalent.
- Return type:
boolean
- factorize(na_sentinel: int = -1) tuple[np.ndarray, ExtensionArray]¶
Encode the extension array as an enumerated type.
- Parameters:
na_sentinel (int, default -1) – Value to use in the codes array to indicate missing values.
- Returns:
codes (ndarray) – An integer NumPy array that’s an indexer into the original ExtensionArray.
uniques (ExtensionArray) – 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.
See also
factorizeTop-level factorize method that dispatches here.
Notes
pandas.factorize()offers a sort keyword as well.
- fillna(value: object | ArrayLike | None = None, method: FillnaOptions | None = None, limit: int | None = None)¶
Fill NA/NaN values using the specified method.
- Parameters:
value (scalar, 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.
limit (int, 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.
- Returns:
With NA/NaN filled.
- Return type:
ExtensionArray
- isin(values) ndarray¶
Pointwise comparison for set containment in the given values.
Roughly equivalent to np.array([x in values for x in self])
- Parameters:
values (Sequence) –
- Return type:
np.ndarray[bool]
- isna() Union[ExtensionArray, ndarray][source]¶
A 1-D array indicating if each value is missing. :returns: na_values – 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.- Return type:
Union[np.ndarray, ExtensionArray]
Notes
If returning an ExtensionArray, then *
na_values._is_booleanshould be True * na_values should implementExtensionArray._reduce()*na_values.anyandna_values.allshould be implemented
- ravel(order: Literal['C', 'F', 'A', 'K'] | None = 'C') ExtensionArray¶
Return a flattened view on this array.
- Parameters:
order ({None, 'C', 'F', 'A', 'K'}, default 'C') –
- Return type:
ExtensionArray
Notes
Because ExtensionArrays are 1D-only, this is a no-op.
The “order” argument is ignored, is for compatibility with NumPy.
- repeat(repeats: int | Sequence[int], axis: int | None = 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.
- Parameters:
repeats (int 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.
axis (None) – Must be
None. Has no effect but is accepted for compatibility with numpy.
- Returns:
repeated_array – Newly created ExtensionArray with repeated elements.
- Return type:
ExtensionArray
See also
Series.repeatEquivalent function for Series.
Index.repeatEquivalent function for Index.
numpy.repeatSimilar method for
numpy.ndarray.ExtensionArray.takeTake arbitrary positions.
Examples
>>> 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.
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]- Parameters:
value (array-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).
sorter (1-D array-like, optional) – Optional array of integer indices that sort array a into ascending order. They are typically the result of argsort.
- Returns:
Array of insertion points with the same shape as value.
- Return type:
array of ints
See also
numpy.searchsortedSimilar method from NumPy.
- shift(periods: int = 1, fill_value: Optional[object] = None) ExtensionArray¶
Shift values by desired number.
Newly introduced missing values are filled with
self.dtype.na_value.- Parameters:
periods (int, default 1) – The number of periods to shift. Negative values are allowed for shifting backwards.
fill_value (object, optional) – The scalar value to use for newly introduced missing values. The default is
self.dtype.na_value.
- Returns:
Shifted.
- Return type:
ExtensionArray
Notes
If
selfis empty orperiodsis 0, a copy ofselfis returned.If
periods > len(self), then an array of size len(self) is returned, with all values filled withself.dtype.na_value.
- take(indices: Sequence[int], allow_fill: bool = False, fill_value: Optional[Any] = None) ExtensionArray[source]¶
Take elements from an array. :param indices: Indices to be taken. :type indices: sequence of int :param allow_fill: 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.
- Parameters:
fill_value (any, 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.- Return type:
ExtensionArray
- Raises:
IndexError – When the indices are out of bounds for the array.
ValueError – When indices contains negative values other than
-1and allow_fill is True.
See also
numpy.take,api.extensions.takeNotes
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.Examples
Here’s an example implementation, which relies on casting the extension array to object dtype. This uses the helper method
pandas.api.extensions.take(). .. code-block:: python- 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_ip()[source]¶
Return a Data Collection in IP units
- Returns:
LadybugArrayType – A Ladybug Array converted to the desired unit
- to_numpy(dtype: Dtype | None = None, copy: bool = False, na_value=NoDefault.no_default) np.ndarray¶
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.- Parameters:
dtype (str or numpy.dtype, optional) – The dtype to pass to
numpy.asarray().copy (bool, default False) – Whether to ensure that the returned value is a not a view on another array. Note that
copy=Falsedoes not ensure thatto_numpy()is no-copy. Rather,copy=Trueensure that a copy is made, even if not strictly necessary.na_value (Any, optional) – The value to use for missing values. The default value depends on dtype and the type of the array.
- Return type:
numpy.ndarray
- to_si()[source]¶
Return a Data Collection in SI units
- Returns:
LadybugArrayType – A Ladybug Array converted to the desired unit
- to_unit(unit)[source]¶
Return a Data Collection in the input unit
- Parameters:
type (unit {str} -- A unit string that exists for the data) –
- Returns:
LadybugArrayType – A Ladybug Array converted to the desired unit
- transpose(*axes: int) ExtensionArray¶
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.
- unique() ExtensionArrayT¶
Compute the ExtensionArray of unique values.
- Returns:
uniques
- Return type:
ExtensionArray
- value_counts(dropna=True)[source]¶
Return a Series containing counts of unique values.
- Parameters:
dropna (bool, default True) – Don’t include counts of NaT values.
- Return type:
- view(dtype=None) Union[ABCExtensionArray, ndarray][source]¶
Return a view on the array.
- Parameters:
dtype (str, np.dtype, or ExtensionDtype, optional) – Default None.
- Returns:
A view of the
ExtensionArray.- Return type:
ExtensionArray
- property T: ExtensionArray¶
- property dtype: ExtensionDtype¶
An instance of ‘ExtensionDtype’.
- property nbytes: int¶
The number of bytes needed to store this object in memory.
- property ndim: int¶
Extension Arrays are only allowed to be 1-dimensional.
- property shape: Tuple[int, ...]¶
Return a tuple of the array dimensions.
- property size: int¶
The number of elements in the array.