Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold committed Dec 11, 2024
1 parent 1fcfb5f commit b43ddd5
Show file tree
Hide file tree
Showing 2 changed files with 481 additions and 21 deletions.
63 changes: 42 additions & 21 deletions lib/catalog/owid/catalog/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,12 @@ def read(cls, path: Union[str, Path], **kwargs) -> "Table":
return table

@overload
def to_csv(self, path: None = None, **kwargs: Any) -> str: ...
def to_csv(self, path: None = None, **kwargs: Any) -> str:
...

@overload
def to_csv(self, path: Any, **kwargs: Any) -> None: ...
def to_csv(self, path: Any, **kwargs: Any) -> None:
...

def to_csv(self, path: Optional[Any] = None, **kwargs: Any) -> Union[None, str]:
"""
Expand Down Expand Up @@ -449,13 +451,16 @@ def rename(
*,
inplace: Literal[True],
**kwargs: Any,
) -> None: ...
) -> None:
...

@overload
def rename(self, mapper: Any = None, *, inplace: Literal[False], **kwargs: Any) -> "Table": ...
def rename(self, mapper: Any = None, *, inplace: Literal[False], **kwargs: Any) -> "Table":
...

@overload
def rename(self, *args: Any, **kwargs: Any) -> "Table": ...
def rename(self, *args: Any, **kwargs: Any) -> "Table":
...

def rename(self, *args: Any, **kwargs: Any) -> Optional["Table"]:
"""Rename columns while keeping their metadata."""
Expand Down Expand Up @@ -560,13 +565,16 @@ def set_index(
*,
inplace: Literal[True],
**kwargs: Any,
) -> None: ...
) -> None:
...

@overload
def set_index(self, keys: Union[str, List[str]], *, inplace: Literal[False], **kwargs: Any) -> "Table": ...
def set_index(self, keys: Union[str, List[str]], *, inplace: Literal[False], **kwargs: Any) -> "Table":
...

@overload
def set_index(self, keys: Union[str, List[str]], **kwargs: Any) -> "Table": ...
def set_index(self, keys: Union[str, List[str]], **kwargs: Any) -> "Table":
...

def set_index(
self,
Expand All @@ -586,13 +594,16 @@ def set_index(
return cast(Table, t)

@overload
def reset_index(self, level=None, *, inplace: Literal[True], **kwargs) -> None: ...
def reset_index(self, level=None, *, inplace: Literal[True], **kwargs) -> None:
...

@overload
def reset_index(self, level=None, *, inplace: Literal[False], **kwargs) -> "Table": ...
def reset_index(self, level=None, *, inplace: Literal[False], **kwargs) -> "Table":
...

@overload
def reset_index(self, level=None, *, inplace: bool = False, **kwargs) -> "Table": ...
def reset_index(self, level=None, *, inplace: bool = False, **kwargs) -> "Table":
...

def reset_index(self, level=None, *, inplace: bool = False, **kwargs) -> Optional["Table"]: # type: ignore
"""Fix type signature of reset_index."""
Expand All @@ -612,13 +623,16 @@ def reindex(self, *args, **kwargs) -> "Table":
return cast(Table, t)

@overload
def drop_duplicates(self, *, inplace: Literal[True], **kwargs) -> None: ...
def drop_duplicates(self, *, inplace: Literal[True], **kwargs) -> None:
...

@overload
def drop_duplicates(self, *, inplace: Literal[False], **kwargs) -> "Table": ...
def drop_duplicates(self, *, inplace: Literal[False], **kwargs) -> "Table":
...

@overload
def drop_duplicates(self, **kwargs) -> "Table": ...
def drop_duplicates(self, **kwargs) -> "Table":
...

def drop_duplicates(self, *args, **kwargs) -> Optional["Table"]:
return super().drop_duplicates(*args, **kwargs)
Expand Down Expand Up @@ -809,13 +823,16 @@ def format(
return t

@overload
def dropna(self, *, inplace: Literal[True], **kwargs) -> None: ...
def dropna(self, *, inplace: Literal[True], **kwargs) -> None:
...

@overload
def dropna(self, *, inplace: Literal[False], **kwargs) -> "Table": ...
def dropna(self, *, inplace: Literal[False], **kwargs) -> "Table":
...

@overload
def dropna(self, **kwargs) -> "Table": ...
def dropna(self, **kwargs) -> "Table":
...

def dropna(self, *args, **kwargs) -> Optional["Table"]:
tb = super().dropna(*args, **kwargs)
Expand Down Expand Up @@ -1061,10 +1078,12 @@ def __init__(self, groupby: pd.core.groupby.DataFrameGroupBy, metadata: TableMet
self._fields = fields

@overload
def __getattr__(self, name: Literal["count", "size", "sum", "mean", "median"]) -> Callable[[], "Table"]: ...
def __getattr__(self, name: Literal["count", "size", "sum", "mean", "median"]) -> Callable[[], "Table"]:
...

@overload
def __getattr__(self, name: str) -> "VariableGroupBy": ...
def __getattr__(self, name: str) -> "VariableGroupBy":
...

def __getattr__(self, name: str) -> Union[Callable[..., "Table"], "VariableGroupBy"]:
# Calling method on the groupby object
Expand Down Expand Up @@ -1095,10 +1114,12 @@ def func(*args, **kwargs):
return VariableGroupBy(getattr(self.groupby, name), name, self._fields[name], self.metadata)

@overload
def __getitem__(self, key: str) -> "VariableGroupBy": ...
def __getitem__(self, key: str) -> "VariableGroupBy":
...

@overload
def __getitem__(self, key: list) -> "TableGroupBy": ...
def __getitem__(self, key: list) -> "TableGroupBy":
...

def __getitem__(self, key: Union[str, list]) -> Union["VariableGroupBy", "TableGroupBy"]:
if isinstance(key, list):
Expand Down
Loading

0 comments on commit b43ddd5

Please sign in to comment.