Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

267 to pandas as function #272

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/fmu/sumo/explorer/objects/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def dataframe(self) -> pd.DataFrame:
DeprecationWarning,
stacklevel=2,
)
return self.to_pandas
return self.to_pandas()


@property
def to_pandas(self) -> pd.DataFrame:
"""Return object as a pandas DataFrame

Expand Down Expand Up @@ -106,9 +106,6 @@ async def to_pandas_async(self) -> pd.DataFrame:
self._logger.debug("Read blob as %s to return pandas", worked)
return self._dataframe

@to_pandas.setter
def to_pandas(self, frame: pd.DataFrame):
self._dataframe = frame

@property
def arrowtable(self) -> pa.Table:
Expand Down
82 changes: 51 additions & 31 deletions tests/test_aggregated_table.py → tests/test_objects_table.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@
"""Testing of Aggregated table class"""
"""Test table objects.

* Table
* AggregatedTable
* TableCollection

"""
import pandas as pd
import pyarrow as pa
from fmu.sumo.explorer import Explorer, AggregatedTable
import pytest

# Fixed test case ("Drogon_AHM_2023-02-22") in Sumo/DEV
TESTCASE_UUID = "10f41041-2c17-4374-a735-bb0de62e29dc"

@pytest.fixture(name="explorer")
def fixture_explorer(token: str) -> Explorer:
"""Returns explorer"""
return Explorer("dev", token=token)

@pytest.fixture(name="case")
def fixture_case(explorer: Explorer):
"""Return fixed testcase."""
return explorer.get_case_by_uuid(TESTCASE_UUID)

# @pytest.fixture(name="case")
# def case_fixture():
# """Init of case"""
# exp = Explorer("dev")
# case = exp.cases.filter(name="drogon_ahm-2023-02-22")[0]
# return case
@pytest.fixture(name="table")
def fixture_table(case):
"""Get one table for further testing."""
return case.tables[0]

### Table

def test_table_dataframe(table):
"""Test the dataframe property."""
with pytest.warns(DeprecationWarning, match=".dataframe is deprecated"):
df = table.dataframe
assert isinstance(df, pd.DataFrame)

def test_aggregated_summary_arrow(explorer: Explorer):
"""Test usage of Aggregated class with default type"""

case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0]
def test_table_to_pandas(table):
"""Test the to_pandas method."""
df = table.to_pandas()
assert isinstance(df, pd.DataFrame)


def test_arrowtable(table):
"""Test the arrowtable property."""
with pytest.warns(DeprecationWarning, match=".arrowtable is deprecated"):
arrow = table.arrowtable
assert isinstance(arrow, pa.Table)


def test_table_to_arrow(table):
"""Test the to_arrow() method"""
arrow = table.to_arrow()
assert isinstance(arrow, pa.Table)


### Aggregated Table

def test_aggregated_summary_arrow(case):
"""Test usage of Aggregated class with default type"""

table = AggregatedTable(case, "summary", "eclipse", "iter-0")

Expand All @@ -37,13 +74,9 @@ def test_aggregated_summary_arrow(explorer: Explorer):
)


def test_aggregated_summary_arrow_with_deprecated_function_name(
explorer: Explorer,
):
def test_aggregated_summary_arrow_with_deprecated_function_name(case):
"""Test usage of Aggregated class with default type with deprecated function name"""

case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0]

table = AggregatedTable(case, "summary", "eclipse", "iter-0")

assert len(table.columns) == 972 + 2
Expand All @@ -61,26 +94,13 @@ def test_aggregated_summary_arrow_with_deprecated_function_name(
)


def test_aggregated_summary_pandas(explorer: Explorer):
def test_aggregated_summary_pandas(case):
"""Test usage of Aggregated class with item_type=pandas"""
case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0]
table = AggregatedTable(case, "summary", "eclipse", "iter-0")
assert isinstance(table["FOPT"].to_pandas, pd.DataFrame)


def test_aggregated_summary_pandas_with_deprecated_function_name(
explorer: Explorer,
):
"""Test usage of Aggregated class with item_type=pandas with deprecated function name"""
case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0]
table = AggregatedTable(case, "summary", "eclipse", "iter-0")
with pytest.warns(match=".dataframe is deprecated, renamed to .to_pandas()"):
mydata = table["FOPT"].dataframe
assert isinstance(mydata, pd.DataFrame)
assert isinstance(table["FOPT"].to_pandas(), pd.DataFrame)


def test_get_fmu_iteration_parameters(explorer: Explorer):
def test_get_fmu_iteration_parameters(case):
"""Test getting the metadata of of an object"""
case = explorer.cases.filter(name="drogon_ahm-2023-02-22")[0]
table = AggregatedTable(case, "summary", "eclipse", "iter-0")
assert isinstance(table.parameters, dict)