Skip to content

Commit

Permalink
210 indexing obscollection always returns obs column (#220)
Browse files Browse the repository at this point in the history
* rewrite __init__ to fix #210

* add kwargs to dataframe constructor

* fix failing tests

* remove pandas requirement
  • Loading branch information
OnnoEbbens authored Jun 25, 2024
1 parent 2dc65a2 commit 61f844d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions hydropandas/obs_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ def __init__(self, *args, **kwargs):
if len(args) == 0:
logger.debug("Create empty ObsCollection")
super().__init__(**kwargs)
elif 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)):
logger.debug("Convert list of observations to ObsCollection")
obs_df = util._obslist_to_frame(args[0])
Expand All @@ -856,12 +861,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, **kwargs)
super().__init__(df, **kwargs)
else:
super().__init__(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ maintainers = [
{ name = "M.A. Vonk", email = "m.vonk@artesia-water.nl" },
]
requires-python = ">=3.9"
dependencies = ["scipy", "pandas <= 2.2.1", "matplotlib", "tqdm", "requests", "colorama"]
dependencies = ["scipy", "pandas", "matplotlib", "tqdm", "requests", "colorama"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_003_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_get_ground_level_gwobs():
try:
from art_tools import hpd_extension # noqa: F401

gw = ttf.observation_gw_old()
gw = ttf.observation_gw_dino_old()
gw.art.geo_get_ground_level()
return
except ModuleNotFoundError as e:
Expand Down

0 comments on commit 61f844d

Please sign in to comment.