-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
1,938 additions
and
1,893 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
solidago/src/solidago/primitives/datastructure/unnamed_dataframe_dict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Union, Optional, Callable, Any, Iterable | ||
from types import BuiltinFunctionType, SimpleNamespace | ||
from pathlib import Path | ||
from pandas import DataFrame, Series | ||
from functools import reduce | ||
|
||
import pandas as pd | ||
|
||
|
||
class UnnamedDataFrameDict: | ||
|
||
def __init__(self, | ||
*args, | ||
df_cls: type=DataFrame, | ||
main_key_names=list[str], | ||
sub_key_names=list[str], | ||
**kwargs | ||
): | ||
self.dict = dict(*args, **kwargs) | ||
self.df_cls = df_cls | ||
self.main_key_names = main_key_names | ||
self.sub_key_names = sub_key_names | ||
|
||
def __getitem__(self, key: Union[Any, tuple[str]]) -> DataFrame: | ||
keys = tuple(str(k) for k in key) if isinstance(key, tuple) else str(key) | ||
return self.dict[keys] if keys in self.dict else self.df_cls() | ||
|
||
def __repr__(self) -> str: | ||
return "\n\n".join([ f"{key}:\n{value}" for key, value in self.dict.items() ]) | ||
|
||
def __iter__(self) -> Iterable: | ||
for keys, value in self.dict.items(): | ||
yield keys, value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.