RedBlackPy 0.1.3

Table of contents:

Main
Initialization
Interpolation
Iterators
Arithmetic

Series User Guide

Note. This page is on developing stage!


Initialization

You can construct Series object by the following ways:

import datetime as dt
import redblackpy as rb

# one day
step = dt.timedelta(1,0,0)
# index as list of datetimes
index = [ (dt.datetime(2018, 1, 1) + step*i) for i in range(10) ]
# values as integers 
values = range(10)
# creating a Series
series = rb.Series(index, values, dtype="int32", name="myseries" )


Interpolation

Series provides several interpolation types: floor, ceil, nn, error(keys only).

import datetime as dt
import redblackpy as rb

# tow days
step = dt.timedelta(2,0,0)
# index as list of datetimes
index = [ (dt.datetime(2018, 1, 1) + step*i) for i in range(10) ]
# values as integers 
values = range(10)
# creating a Series
series = rb.Series(index, values, dtype="int32", name="myseries" )

# call getitem on dt.datetime(2018, 1, 2) which doesn't exist in series
# prints 0 - value for dt.datetime(2018,1,1), as floor interpolation is default.
print( series[dt.datetime(2018,1,2)] )

# set ceil interpolation
series.set_interpolation('ceil')

# call getitem on dt.datetime(2018, 1, 2) which doesn't exist in series
# prints 1 - value for dt.datetime(2018,1,3), as now ceil interpolation is set.
print( series[dt.datetime(2018,1,2)] )

SeriesIterator

import redblackpy as rb
import random

def create_random_series(length):
  
  data = random.sample(range(5000000), length)
  # with no loss of generality using one list for index and values
  return rb.Series(index=data, values=data, dtype='int64')


#------------------------------------------------------------------------
# create timer for executing time evaluation
timer = rb.Timer()

# create list of 10 Series, each contains 100k values
series_list = [ create_random_series(100000) for i in range(10) ]

# start time evaluation, we including initialization of SeriesIterator
timer.start()
iterator = rb.SeriesIterator(series_list)
# iterating over union of ten Series
for key in iterator():
  key
# stop timer  
time_forward = timer.stop()

# the same procedure, but for reverse iterator
timer.start()
# iterating over union of ten Series
for key in iterator('reverse'):
  key
# stop timer  
time_reverse = timer.stop()
# obtain the results
output_str = 'Time forward: {:}; Time reverse: {:}'.format( time_forward, 
                                                            time_reverse )
print(output_str)