Skip to content

Commit

Permalink
0.2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
fenke committed Jun 10, 2024
1 parent c3aaeae commit 45ae9f3
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 13 deletions.
2 changes: 1 addition & 1 deletion corebridge/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.10"
__version__ = "0.2.13"
8 changes: 4 additions & 4 deletions corebridge/aicorebridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def get_callargs(self:AICoreModule, **kwargs):

return {
K:self.processor_signature.parameters[K].annotation(
kwargs.get(
self.init_kwargs.get(
K,
metadata.get(
K,
self.init_kwargs.get(
kwargs.get(
K,
metadata.get(
K,
self.processor_signature.parameters[K].default
)
Expand Down
12 changes: 6 additions & 6 deletions corebridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
except:
pass

# %% ../nbs/00_core.ipynb 6
# %% ../nbs/00_core.ipynb 7
def set_time_index_zone(df:pd.DataFrame, timezone):
if isinstance(df.index, pd.DatetimeIndex):
df.index.name = 'time'
if not hasattr(df.index, 'tz'):
if not hasattr(df.index, 'tz') or not df.index.tz or not df.index.tz:
df.index = df.index.tz_localize('UTC').tz_convert(timezone)
elif str(df.index.tz) != timezone:
df.index = df.index.tz_convert(timezone)

return df


# %% ../nbs/00_core.ipynb 7
# %% ../nbs/00_core.ipynb 9
def timeseries_dataframe(
data:typing.Union[pd.DataFrame, pd.Series, dict, np.ndarray, np.recarray],
timezone='UTC',
columnnames=None):

"""Convert various data formats to timeseries DataFrame"""
"""Convert various tabular data formats to timeseries DataFrame"""

if isinstance(data, pd.DataFrame):
df = data
Expand Down Expand Up @@ -76,7 +76,7 @@ def timeseries_dataframe(

return set_time_index_zone(df, timezone)

# %% ../nbs/00_core.ipynb 8
# %% ../nbs/00_core.ipynb 11
def timeseries_dataframe_from_datadict(
data:dict,
timecolumns,
Expand Down Expand Up @@ -107,7 +107,7 @@ def timeseries_dataframe_from_datadict(
return df


# %% ../nbs/00_core.ipynb 9
# %% ../nbs/00_core.ipynb 15
def timeseries_dataframe_to_datadict(
data:typing.Union[pd.DataFrame, pd.Series, dict],
recordformat:str='split',
Expand Down
176 changes: 175 additions & 1 deletion nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"def set_time_index_zone(df:pd.DataFrame, timezone):\n",
" if isinstance(df.index, pd.DatetimeIndex):\n",
" df.index.name = 'time'\n",
" if not hasattr(df.index, 'tz'):\n",
" if not hasattr(df.index, 'tz') or not df.index.tz or not df.index.tz:\n",
" df.index = df.index.tz_localize('UTC').tz_convert(timezone)\n",
" elif str(df.index.tz) != timezone:\n",
" df.index = df.index.tz_convert(timezone)\n",
Expand Down Expand Up @@ -160,6 +160,13 @@
" return set_time_index_zone(df, timezone)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -197,6 +204,173 @@
" return df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>value</th>\n",
" </tr>\n",
" <tr>\n",
" <th>time</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2023-05-04 10:04:49+00:00</th>\n",
" <td>16.72</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-05-04 10:24:51+00:00</th>\n",
" <td>16.65</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-05-04 10:44:53+00:00</th>\n",
" <td>16.55</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" value\n",
"time \n",
"2023-05-04 10:04:49+00:00 16.72\n",
"2023-05-04 10:24:51+00:00 16.65\n",
"2023-05-04 10:44:53+00:00 16.55"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"timeseries_dataframe_from_datadict([\n",
" {\n",
" \"time\":\"2023-05-04T10:04:49.000Z\",\n",
" \"value\":16.72\n",
" },\n",
" {\n",
" \"time\":\"2023-05-04T10:24:51.000Z\",\n",
" \"value\":16.65\n",
" },\n",
" {\n",
" \"time\":\"2023-05-04T10:44:53.000Z\",\n",
" \"value\":16.55\n",
" }\n",
" ], timecolumns=['time'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>value</th>\n",
" </tr>\n",
" <tr>\n",
" <th>time</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2023-05-04 12:04:49+02:00</th>\n",
" <td>16.72</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-05-04 12:24:51+02:00</th>\n",
" <td>16.65</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-05-04 12:44:53+02:00</th>\n",
" <td>16.55</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" value\n",
"time \n",
"2023-05-04 12:04:49+02:00 16.72\n",
"2023-05-04 12:24:51+02:00 16.65\n",
"2023-05-04 12:44:53+02:00 16.55"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_time_index_zone( timeseries_dataframe_from_datadict([\n",
" {\n",
" \"time\":\"2023-05-04T10:04:49\",\n",
" \"value\":16.72\n",
" },\n",
" {\n",
" \"time\":\"2023-05-04T10:24:51\",\n",
" \"value\":16.65\n",
" },\n",
" {\n",
" \"time\":\"2023-05-04T10:44:53\",\n",
" \"value\":16.55\n",
" }\n",
" ], timecolumns=['time']), timezone='Europe/Amsterdam')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
1 change: 1 addition & 0 deletions nbs/01_aicorebridge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
" return {\n",
" K:self.processor_signature.parameters[K].annotation(\n",
" self.init_kwargs.get(\n",
" K,\n",
" kwargs.get(\n",
" K,\n",
" metadata.get(\n",
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Python library ###
repo = corebridge
lib_name = %(repo)s
version = 0.2.10
version = 0.2.13
min_python = 3.7
license = apache2
black_formatting = False
Expand Down

0 comments on commit 45ae9f3

Please sign in to comment.