Skip to content

Commit

Permalink
Merge pull request #419 from DHI/default-plot
Browse files Browse the repository at this point in the history
plot() should raise error if no default plot
  • Loading branch information
jsmariegaard authored Sep 20, 2024
2 parents 285ce7f + 735e0f0 commit fcb0eba
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions modelskill/skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def _get_plot_df(self, level: int | str = 0) -> pd.DataFrame:

# return gdf.explore(column=column, **kwargs)

def __call__(self, *args: Any, **kwds: Any) -> Any:
raise NotImplementedError(
"It is not possible to call plot directly (has no default)! Use one of the plot methods explicitly e.g. plot.line() or plot.bar()"
)

def line(
self,
level: int | str = 0,
Expand Down Expand Up @@ -281,6 +286,11 @@ def _deprecated_warning(method, field): # type: ignore
FutureWarning,
)

def __call__(self, *args: Any, **kwds: Any) -> Any:
raise NotImplementedError(
"It is not possible to call plot directly on SkillTable! Select metric first (which gives a plotable SkillArray)"
)

def line(self, field, **kwargs): # type: ignore
self._deprecated_warning("line", field) # type: ignore
return self.skilltable[field].plot.line(**kwargs)
Expand Down Expand Up @@ -312,7 +322,7 @@ class SkillArray:
def __init__(self, data: pd.DataFrame) -> None:
self.data = data
self._ser = data.iloc[:, -1] # last column is the metric

self.plot = SkillArrayPlotter(self)
"""Plot using the SkillArrayPlotter
Expand Down Expand Up @@ -511,12 +521,10 @@ def _repr_html_(self) -> Any:
return self._df._repr_html_()

@overload
def __getitem__(self, key: Hashable | int) -> SkillArray:
...
def __getitem__(self, key: Hashable | int) -> SkillArray: ...

@overload
def __getitem__(self, key: Iterable[Hashable]) -> SkillTable:
...
def __getitem__(self, key: Iterable[Hashable]) -> SkillTable: ...

def __getitem__(
self, key: Hashable | Iterable[Hashable]
Expand Down Expand Up @@ -559,7 +567,7 @@ def iloc(self, *args, **kwargs): # type: ignore

@property
def loc(self, *args, **kwargs): # type: ignore
return self.data.loc(*args, **kwargs)
return self.data.loc(*args, **kwargs)

def sort_index(self, *args, **kwargs) -> SkillTable: # type: ignore
"""Sort by index (level) e.g. sorting by observation
Expand Down

0 comments on commit fcb0eba

Please sign in to comment.