Skip to content

Commit

Permalink
Drop ValueError on empty columns
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Aug 13, 2024
1 parent e8370c9 commit c10289c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
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

0 comments on commit c10289c

Please sign in to comment.