bgc_data_processing.utils.dateranges
¶
Date range generating objects.
DateRangeGenerator(start, end, interval, interval_length=1)
¶
Generate date ranges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
datetime
|
Starting date of the range. |
required |
end |
datetime
|
Ending date of the range. |
required |
interval |
str
|
Type of interval, 'day', 'week', 'month', 'year' or 'custom'. |
required |
interval_length |
int
|
Length of custom interval, in days., by default 1 |
1
|
Generate date ranges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
datetime
|
Starting date of the range. |
required |
end |
datetime
|
Ending date of the range. |
required |
interval |
str
|
Type of interval, 'day', 'week', 'month', 'year' or 'custom'. |
required |
interval_length |
int
|
Length of custom interval, in days., by default 1 |
1
|
Source code in src/bgc_data_processing/utils/dateranges.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
freqs: dict[str, str] = {'day': 'D', 'week': 'W', 'month': 'M', 'year': 'Y'}
class-attribute
¶
start_column_name: str = 'start_date'
class-attribute
instance-attribute
¶
end_column_name: str = 'end_date'
class-attribute
instance-attribute
¶
start = pd.to_datetime(start).normalize()
instance-attribute
¶
end = pd.to_datetime(end).normalize()
instance-attribute
¶
interval = interval
instance-attribute
¶
interval_length = interval_length
instance-attribute
¶
__call__()
¶
Load the date ranges.
Returns:
Type | Description |
---|---|
DataFrame
|
Range DataFrame with self.start_column_name and self.end_column_name columns. Both start and end dates are supposed to be included in the final range. |
Source code in src/bgc_data_processing/utils/dateranges.py
59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
DateRange(data, start_col, end_col)
¶
Class to hold dateranges dataframes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
The actual daterange dataframe. |
required |
start_col |
str
|
Name of the column with starting dates. |
required |
end_col |
str
|
Name of the column with ending dates. |
required |
Source code in src/bgc_data_processing/utils/dateranges.py
163 164 165 166 |
|
start_field: str
property
¶
Satrting date column name.
end_field: str
property
¶
Ending date column name.
start_dates: pd.Series
property
¶
Starting date column.
end_dates: pd.Series
property
¶
Ending date column.
as_dataframe()
¶
Return the dateranges as a DataFrame, ie self._data.
Source code in src/bgc_data_processing/utils/dateranges.py
188 189 190 |
|
as_str()
¶
Return a Series of dateranges as strings with format: 'YYYYMMDD-YYYYMMDD'.
Source code in src/bgc_data_processing/utils/dateranges.py
192 193 194 195 196 |
|