diff --git a/python/resdata/summary/rd_sum.py b/python/resdata/summary/rd_sum.py index 50f575dba..ae10c0e66 100644 --- a/python/resdata/summary/rd_sum.py +++ b/python/resdata/summary/rd_sum.py @@ -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) @@ -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)]) diff --git a/python/tests/rd_tests/test_rd_sum.py b/python/tests/rd_tests/test_rd_sum.py index a23a3a113..e0dac8b7d 100644 --- a/python/tests/rd_tests/test_rd_sum.py +++ b/python/tests/rd_tests/test_rd_sum.py @@ -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 + ) diff --git a/python/tests/rd_tests/test_sum.py b/python/tests/rd_tests/test_sum.py index ac3211591..198f4627e 100644 --- a/python/tests/rd_tests/test_sum.py +++ b/python/tests/rd_tests/test_sum.py @@ -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)