Module pyprotolinc.portfolio

This module provides classes and method that allow to read in seriatim records from Excel files and perform initial transformations and validations on them.

class pyprotolinc.portfolio.Portfolio(portfolio_path: Optional[str], states_model: type[pyprotolinc.models.state_models.AbstractStateModel], df_portfolio: Optional[DataFrame] = None)

Representation of a seriatim portfolio.

split_by_product_and_month_in_year(chunk_size: int, split_mont_in_year: bool = True) list['Portfolio']

Return a list of sub-portfolios which are homgeneous w.r.t. to the ages in months modulo 12.

class pyprotolinc.portfolio.PortfolioLoader(portfolio_path: str, portfolio_cache: Optional[str] = None)

Loader object for portfolio from Excel file that implements a cache.

load(states_model: type[pyprotolinc.models.state_models.AbstractStateModel]) Portfolio

Load the portfolio from cache or file. this will include data validations.

:param states_model The State model class against which the status are validated.

pyprotolinc.portfolio.completed_months_to_date(date_col_in: ndarray[Any, dtype[datetime64]], the_date_in: Union[datetime, ndarray[Any, dtype[datetime64]]]) ndarray[Any, dtype[int32]]

Calculate completed months between the date_col and (the later) the_date. The latter one can be a np.datetime series or a datetime.datetime.

Returns -1 where date_col_in is NA

pyprotolinc.portfolio.split_to_size(df_portfolio: DataFrame, max_size: int) list[pandas.core.frame.DataFrame]

Split a dataframe into subsets with a maximum size.