Skip to content

Commit

Permalink
rewrite __init__ to fix #210
Browse files Browse the repository at this point in the history
  • Loading branch information
OnnoEbbens committed Jun 24, 2024
1 parent 2dc65a2 commit 8e8f5af
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions hydropandas/obs_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,9 @@ def __init__(self, *args, **kwargs):
self.name = kwargs.pop("name", "")
self.meta = kwargs.pop("meta", {})

if len(args) == 0:
if isinstance(args[0], ObsCollection):
super().__init__(*args, **kwargs)
elif len(args) == 0:
logger.debug("Create empty ObsCollection")
super().__init__(**kwargs)
elif isinstance(args[0], (list, tuple)):
Expand All @@ -856,12 +858,11 @@ def __init__(self, *args, **kwargs):
remaining_args = [o for o in args if not isinstance(o, obs.Obs)]
obs_df = util._obslist_to_frame(obs_list)
super().__init__(obs_df, *remaining_args, **kwargs)
elif isinstance(args[0], pd.DataFrame):
if "obs" not in args[0].columns:
df = self.from_dataframe(*args)
super().__init__(df, **kwargs)
else:
super().__init__(*args, **kwargs)
elif isinstance(args[0], pd.DataFrame) and (
"obs_list" in kwargs or "ObsClass" in kwargs
):
df = self.from_dataframe(*args)
super().__init__(df, **kwargs)
else:
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit 8e8f5af

Please sign in to comment.