Analyze stock
Project description
kabutobashi
Core Concept
@block
-decorator and Flow
-class is important.
@block
automatically generates input and output functions, allowing you to focus solely on the processing.
Flow
allows you to focus solely on the process flow and input parameters.
About @block
-decorator
simple decorator is like below.
def simple_decorator(func):
def wrap_func() -> str:
res = func()
return f"Hello, {res}"
return wrap_func
@simple_decorator
def world() -> str:
return "world"
world() # => "Hello, world"
A decorator
is something that dynamically generates and adds processes to functions or classes, similar to its name.
First, prepare a function as follows and decorate it with @block
.
from kabutobashi import block
@block()
class UdfBlock:
term: int = 10
def _process(self):
return {"doubled_term": self.term * 2}
The classes above is equivalent to the following class definition.
import pandas as pd
from kabutobashi.domain.entity.blocks import BlockGlue
class UdfBlock:
series: pd.DataFrame = None
params: dict = None
term: int = 10
block_name: str = "udf_block"
def _process(self):
return {"doubled_term": self.term * 2}
def process(self):
return self._process()
def factory(self, glue: BlockGlue) -> "UdfBlock":
# Omitted. In reality, processes are described.
...
def _factory(self, glue: BlockGlue) -> "UdfBlock":
# Omitted. In reality, processes are described.
...
def glue(self, glue: BlockGlue) -> BlockGlue:
# Omitted. In reality, processes are described.
...
In classes decorated with @block
, it is not recommended to execute the __init__()
method. Instead, it is recommended to use the factory()
class-method.
factory()
method description.
process()
method description.
glue()
method description.
Up to this point, the use of the @block
decorator with classes such as UdfClass has described, but using the Block class on its own is not intended. Please read the following explanation of the Flow
class for more details.
Read-Block
- input
- params
- output
- series
Crawl-Block
- input
- params
- output
- output.params
Extract-Block
- input
- params
- output
- output.params
PreProcess-Block
- input
- series
- params
- output
- series
Process-Block
- input
- series
- params
- output
- output.series
Parameterize-Block
- input
- series
- params
- output
- output.params
Reduce-Block
- input
- series
- params
- output
- params
About Flow
-class
Blocks are meant to be combined.
Processes always consist of combinations of multiple simple operations. And the only tedious part is aligning their inputs and outputs.
Therefore, in Flow
-class, it automatically resolves the sequence of those processes for users, as long as you provide the initial values.
usage
import kabutobashi as kb
# n日前までの営業日の日付リストを取得する関数
target_date = "2020-01-01"
date_list = kb.get_past_n_days(target_date, n=40)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for kabutobashi-0.8.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ec406b169601b0da6acd0a345b1d74d770648975050786bde9c405eba6d053 |
|
MD5 | 6378f31fcee35d61887faf8647afde2a |
|
BLAKE2b-256 | a315a1f9e9d0b4aa6daebfb401dc9d909ce744e3445a0dc5d531f0d266017951 |