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

Summary.pandas_daframe no longer raises ValueError on empty columns #1002

Merged
merged 1 commit into from
Aug 13, 2024
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: 1 addition & 6 deletions python/resdata/summary/rd_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,7 @@ def pandas_frame(self, time_index=None, column_keys=None):
but this can be controlled by using the column_keys argument. The
column_keys should be a list of strings, and each summary vector
matching one of the elements in the @column_keys will get a column in
the frame, you can use wildcards like "WWCT:*" and "*:OP". If you
supply a column_keys argument which does not resolve to any valid
summary keys you will get a ValueError exception.
the frame, you can use wildcards like "WWCT:*" and "*:OP".


sum = Summary(case)
Expand All @@ -601,9 +599,6 @@ def pandas_frame(self, time_index=None, column_keys=None):
for key in column_keys:
keywords.add_keywords(key)

if len(keywords) == 0:
raise ValueError("No valid key")

if time_index is None:
time_index = self.dates
data = numpy.zeros([len(time_index), len(keywords)])
Expand Down
15 changes: 15 additions & 0 deletions python/tests/rd_tests/test_rd_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,18 @@ def test_to_from_pandas(summary):
check_exact=False,
atol=17,
)


@given(summaries())
@pytest.mark.use_fixtures("use_tmpdir")
def test_that_non_matching_dataframe_gives_empty_columns(summary):
smspec, unsmry = summary
assume("BOGUS" not in (smspec.keywords))
smspec.to_file("TEST.SMSPEC")
unsmry.to_file("TEST.UNSMRY")

assert (
Summary("TEST", lazy_load=False)
.pandas_frame(column_keys=["BOGUS"])
.columns.empty
)
6 changes: 0 additions & 6 deletions python/tests/rd_tests/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,6 @@ def test_pandas(self):
self.assertEqual(fopt[0], case.first_value("FOPT"))
self.assertEqual(fopt[-1], case.last_value("FOPT"))

with self.assertRaises(ValueError):
frame = case.pandas_frame(column_keys=[])

with self.assertRaises(ValueError):
frame = case.pandas_frame(column_keys=["NO_KEY"])

frame = case.pandas_frame()
rows, columns = frame.shape
self.assertEqual(len(case.keys()), columns)
Expand Down