pyform.util package

Submodules

pyform.util.dataframe module

pyform.util.dataframe.set_col_as_datetime_index(df: pandas.core.frame.DataFrame, col: str) → pandas.core.frame.DataFrame

Sets a column in the DataFrame as its datetime index, and name the index “datetime”

Parameters
  • df – dataframe to set datetime index

  • col – column to set as the datetime index for the DataFrame

Raises

ValueError – when column cannot be converted to datetime index

Returns

a pandas dataframe with datetime index

Return type

pd.DataFrame

pyform.util.freq module

pyform.util.freq.calc_samples_per_year(num_samples: int, start, end) → float

Computes number of data points per year, given time range

Parameters
  • num_samples – total number of samples

  • start – start date of samples

  • end – end date of samples

Returns

average number of samples per year

Return type

float

pyform.util.freq.calc_timedelta_in_years(start, end) → float
Computes timedelta between start and end dates, in years

To use this function, start and end dates should come from a series of daily frequency.

Parameters
  • start – start date

  • end – end date

Returns

time delta in number of years

Return type

float

pyform.util.freq.infer_freq(series: pandas.core.frame.DataFrame, use: Optional[int] = 50) → str

Infer the frequency of the time series

Parameters
  • series – a pandas DataFrame with datetime index

  • use – number of data points to use from the head and tail of the time series index in order to determin frequency. This should be at least 10. Defaults to 50.

Raises
  • ValueError – when multiple frequencies are detected

  • ValueError – when no frequency can be detected

Returns

frequency of the time series

Return type

str

pyform.util.freq.is_lower_freq(freq1: str, freq2: str) → bool

Tests freq1 has a lower or equal frequency than freq2. Lower frequencies cannot be converted to higher frequencies due to lower resolution.

Parameters
  • freq1 – frequency 1

  • freq2 – frequency 2

Returns

frequency 1 is lower than or euqal to frequency 2

Return type

bool

Module contents