class redblackpy.Series( index=None, values=None, dtype="float32", name="Untitled",
interpolate="floor", extrapolate=0, arithmetic="union" )
Parameter | Description |
---|---|
index |
iterable, container with keys |
values |
iterable, container with values |
dtype |
str, values type |
name |
str, name |
interpolate |
str, interpolation method |
extrapolate |
dtype, extrapolation value |
Attribute | Description |
---|---|
interpolation |
str, interpolation method |
extrapolation |
dtype, extrapolation value |
arithmetic |
str, arithmetic type |
name |
str, name |
dtype |
str, data type |
redblackpy.Series.insert(key, value) \(\rightarrow\) void
value
at key
. If key already exists in Series
object then KeyError
would be thrown. Also, if key
type does not compareble with other keys in Series
object object then KeyError
would be thrown. For example:>>> import redblackpy as rb
>>> series = rb.Series()
>>> series.insert(1, 2)
>>> series.insert(1, 3)
>>> KeyError: 'Key already exists.'
>>>
>>> series.insert('2', 3)
>>> KeyError: 'Your query to tree contains inconsistent key type.'
redblackpy.Series.erase(key) \(\rightarrow\) void
Series
object by key
. If key
does not exist then KeyError
would be thrown.redblackpy.Series.begin() \(\rightarrow\) object
Series
object is empty then IndexError
would be thrown.redblackpy.Series.end() \(\rightarrow\) object
Series
object is empty then IndexError
would be thrown.redblackpy.Series.index() \(\rightarrow\) list
redblackpy.Series.values() \(\rightarrow\) list
redblackpy.Series.iteritems() \(\rightarrow\) generator
tuples(key, value)
.redblackpy.Series.items() \(\rightarrow\) list
tuples(key, value)
.redblackpy.Series.floor(key) \(\rightarrow\) tuple
(key', value)
such that key'
is the greatest key less than or equal to key
.redblackpy.Series.ceil(key) \(\rightarrow\) tuple
(key', value)
such that key'
is the least key greater than or equal to key
.redblackpy.Series.uniform(start, stop, step) \(\rightarrow\) Series
Series
object with uniform grid index. Grid step equals to step
, the first key equals to start
and the last key equals to stop
. Uses the current interpolation type.redblackpy.Series.truncate(start, stop) \(\rightarrow\) Series
Series
object with index from ceil(start)
to floor(stop)
.redblackpy.Series.map(method, inplace=False, args=(), kwargs={}) \(\rightarrow\) Series or void
Apply method
to each value in Series
object. Also you can pass additional arguments through the tuple args
and optional parameters through the kwargs
.
If inplace
is True
then method is applied to the current Series
object and so modifies it. Otherwise, returns new Series
object with result.
redblackpy.Series.set_interpolation(str type) \(\rightarrow\) void
Type | Description |
---|---|
"floor" |
returns value' that corresponding to key' such that key' is the greatest key less than or equal to key . |
"ceil" |
returns value' that corresponding to key' such that key' is the least key greater than or equal to key . |
"nn" |
returns value corresponding the nearest key. |
"linear" |
linear interpolation between two keys. |
"error" |
returns KeyError, getitem works only for keys in index. |
Interpolation is built into the operator getitem
. You can get values by any key using specific interpolation with no use of additional memory. Let's create Series
object, by default it is created with "floor"
interpolation type.
>>> import redblackpy as rb
>>> series = rb.Series(index=[0, 1, 2], values=[4, 6, 8])
>>> series[0]
>>> 4
>>>
>>> series[0.5]
>>> 4.0
>>>
>>> series.interpolation = "linear"
>>> series[0.5]
>>> 5.0
redblackpy.Series.set_extrapolation(dtype value) \(\rightarrow\) void
Set extrapolation value with respect to dtype
. For example, if you call getitem
on key that less than the least in Series
object or more than the greatest key, then getitem
would return extrapolation value. If current interpolation type is "error"
then extrapolation value would be ignored and KeyError
exception would be thrown.
redblackpy.Series.set_arithmetic(str type) \(\rightarrow\) void
Set arithmetic type. Available the following types:
Type | Description |
---|---|
union |
perfoems arithmetic methods along index union of two Series objects. |
left |
performs arithmetic methods along index of left Series object. |
For details, see examples in User guide .
redblackpy.Series.on_itermode() \(\rightarrow\) void
Turn on linear search for operator getitem
. This option makes sense when you iterating over sorted array of keys and call getitem
, Series
object caches result of last call getitem
and starts the next search from cached pointer. In some cases its can effects as 5x speedup,
see User guide and benchmarks .
redblackpy.Series.off_itermode() \(\rightarrow\) void
Turn off linear search for operator getitem
. By default linear search is off and Series
object uses search over a tree.
redblackpy.Series.cast_dtype(str dtype) \(\rightarrow\) void
dtype
. Available the following values types:Unsigned integers | uint8 , uint16 , uint32 , uint64 , uint96 , uint128 |
Signed integers | int8 , int16 , int32 , int64 , int96 , int128 |
Floating point types | float32 , float64 , float80 , float96 , float128 |
Python objects | object , str |
The bits number in some types is depend on your hardware and platform.
redblackpy.Series.to_pandas() \(\rightarrow\) pandas.Series
Convert redbalckpy.Series
object to pandas.Series
object.
@staticmethod
redblackpy.Series.from_pandas(pandas.Series) \(\rightarrow\) redblackpy.Series
redblackpy.Series
object from pandas.Series
object. redblackpy.Series.__del__() \(\rightarrow\) void
Class destructor.
redblackpy.Series.__len__() \(\rightarrow\) int
Returns number of elements.
redblackpy.Series.__str__() \(\rightarrow\) str
Returns string representation of object.
redblackpy.Series.__repr__() \(\rightarrow\) str
Calls redblackpy.Series.__str__()
.
redblackpy.Series.__contains__(key) \(\rightarrow\) bool
Checks if key
in Series
object.
redblackpy.Series.__iter__() \(\rightarrow\) generator
Iterator over values.
redblackpy.Series.__getitem__(key) \(\rightarrow\) dtype or Series
Get value by key
. The key
can be a slice
object.
redblackpy.Series.__setitem__(key, value) \(\rightarrow\) void
Set new value
by key
. If key
already exists then it modifies value, otherwise new element with corresponding key and value would be inserted.
redblackpy.Series.__add__(other) \(\rightarrow\) Series
Add two Series
objects as two vectors. If arithmetic_type
is union
then result Series
object would have index equals to union of two input indexes. If arithmetic_type
is left
then result Series
object would have index equals to index of the current (*this) object.
redblackpy.Series.__sub__(other) \(\rightarrow\) Series
Subtract other
Series
object from current as two vectors. If arithmetic_type
is union
then result Series
object would have index equals to union of two input indexes. If arithmetic_type
is left
then result Series
object would have index equals to index of the current (*this) object.
redblackpy.Series.__mul__(other) \(\rightarrow\) Series
Multiply two Series
objects as two vectors. If arithmetic_type
is union
then result Series
object would have index equals to union of two input indexes. If arithmetic_type
is left
then result Series
object would have index equals to index of the current (*this) object.
redblackpy.Series.__div__(other) \(\rightarrow\) Series
Divide current Series
object by other as two vectors. If arithmetic_type
is union
then result Series
object would have index equals to union of two input indexes. If arithmetic_type
is left
then result Series
object would have index equals to index of the current (*this) object.
redblackpy.Series.__truediv__(other) \(\rightarrow\) Series
Divide current Series
object by other as two vectors. If arithmetic_type
is union
then result Series
object would have index equals to union of two input indexes. If arithmetic_type
is left
then result Series
object would have index equals to index of the current (*this) object.
redblackpy.Series.__lshift__(int shift) \(\rightarrow\) Series
Shift data over index. For details, see User guide .
redblackpy.Series.__rshift__(int shift) \(\rightarrow\) Series
Shift data over index. For details, see User guide .
redblackpy.Series.__getstate__() \(\rightarrow\) dict
redblackpy.Series.__setstate__(dict state) \(\rightarrow\) void