Skip to content

Commit

Permalink
change to isoformat output issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
fenke committed Jan 20, 2025
1 parent 6dfcd27 commit dbc131e
Show file tree
Hide file tree
Showing 5 changed files with 1,030 additions and 1,225 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ nbs/saves/

# Data
*.zip
corebridge/saves/
26 changes: 17 additions & 9 deletions corebridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def set_time_index_zone(df:pd.DataFrame, timezone):
timezone (str): The desired time zone.
Returns:
pd.DataFrame: The DataFrame with its index time zone set to the specified time zone.
pd.DataFrame: The modified DataFrame with its index time zone set
to the specified time zone.
Raises:
None
Expand Down Expand Up @@ -104,10 +105,12 @@ def timeseries_dataframe(
"""

if isinstance(data, pd.DataFrame):
df = data
df = data.copy()
df.index = pd.DatetimeIndex(df.index).round('ms')

elif isinstance(data, pd.Series):
df = pd.DataFrame(data)
df.index = pd.DatetimeIndex(df.index).round('ms')

elif isinstance(data, dict):
# assume a dict/mapping of individual arrays representing timeseries
Expand Down Expand Up @@ -194,7 +197,7 @@ def timeseries_dataframe_from_datadict(
return df


# %% ../nbs/00_core.ipynb 20
# %% ../nbs/00_core.ipynb 23
def pop_nan_values(data):
"""
Recursively pop keys with nan values from dict or lists with dicts.
Expand All @@ -213,7 +216,7 @@ def pop_nan_values(data):
else:
return data

# %% ../nbs/00_core.ipynb 21
# %% ../nbs/00_core.ipynb 35
def timeseries_dataframe_to_datadict(
data:typing.Union[pd.DataFrame, pd.Series, dict],
recordformat:str='records',
Expand All @@ -237,8 +240,13 @@ def timeseries_dataframe_to_datadict(

normalized_data = timeseries_dataframe(data, timezone=timezone)
if isinstance(normalized_data.index, pd.DatetimeIndex):
normalized_data.index = normalized_data.index.map(lambda x: x.isoformat())

if timezone == 'UTC':
print(f"Normalized, UTC")
normalized_data.index = normalized_data.index.strftime("%FT%R:%SZ")
else:
print(f"Normalized, {timezone}")
normalized_data.index = normalized_data.index.map(lambda x: x.isoformat(timespec='milliseconds'))

if orient == 'records':
records = normalized_data.reset_index().to_dict(orient='records')
else:
Expand All @@ -250,7 +258,7 @@ def timeseries_dataframe_to_datadict(
return records


# %% ../nbs/00_core.ipynb 28
# %% ../nbs/00_core.ipynb 51
#def interpolate_timeseries(sampler, period, method_args):


Expand Down Expand Up @@ -295,12 +303,12 @@ def timeseries_dataframe_resample(df:pd.DataFrame, period:str, method:str):



# %% ../nbs/00_core.ipynb 32
# %% ../nbs/00_core.ipynb 55
class AICoreModuleBase:
pass


# %% ../nbs/00_core.ipynb 33
# %% ../nbs/00_core.ipynb 56
@patch
def __init__(self:AICoreModuleBase,
save_dir:str, # path where the module can keep files
Expand Down
Loading

0 comments on commit dbc131e

Please sign in to comment.