From f56fde2413a62948da965badd9b4e2285494f57a Mon Sep 17 00:00:00 2001 From: Alif Be <11570927+alifbe@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:14:53 +0100 Subject: [PATCH] Fix warnings during testing (#681) --- .github/workflows/codecov.yml | 4 ++-- .github/workflows/publish.yml | 4 ++-- .github/workflows/subscript.yml | 4 ++-- src/subscript/casegen_upcars/model.py | 6 +++--- src/subscript/csv_stack/csv_stack.py | 2 +- src/subscript/fmuobs/parsers.py | 2 +- src/subscript/fmuobs/writers.py | 11 +++++++---- src/subscript/interp_relperm/interp_relperm.py | 4 ++-- src/subscript/presentvalue/presentvalue.py | 4 ++-- src/subscript/prtvol2csv/prtvol2csv.py | 6 +++++- tests/test_welltest_dpds.py | 4 ++-- 11 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 46c1471c9..5f8e77874 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -16,10 +16,10 @@ jobs: PYTHON: '3.8' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.8 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7dbc32eb1..cad9bfcd7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,12 +16,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python 3.8 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.8 diff --git a/.github/workflows/subscript.yml b/.github/workflows/subscript.yml index 1a7bc07c8..94a21f271 100644 --- a/.github/workflows/subscript.yml +++ b/.github/workflows/subscript.yml @@ -26,12 +26,12 @@ jobs: steps: - name: Checkout commit locally - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} diff --git a/src/subscript/casegen_upcars/model.py b/src/subscript/casegen_upcars/model.py index 5e0c47f96..901532c1b 100755 --- a/src/subscript/casegen_upcars/model.py +++ b/src/subscript/casegen_upcars/model.py @@ -950,7 +950,7 @@ def set_vug( low=near_fracture_vug_fraction_dist[0], high=near_fracture_vug_fraction_dist[1], size=1, - ) + )[0] * self._total_matrix_cells ) ) @@ -1020,7 +1020,7 @@ def set_vug( low=near_streak_vug_fraction_dist[0], high=near_streak_vug_fraction_dist[1], size=1, - ) + )[0] * self._total_matrix_cells ) ) @@ -1077,7 +1077,7 @@ def set_vug( low=random_vug_fraction_dist[0], high=random_vug_fraction_dist[1], size=1, - ) + )[0] * self._total_matrix_cells ) ) diff --git a/src/subscript/csv_stack/csv_stack.py b/src/subscript/csv_stack/csv_stack.py index e14c96c9e..9755411f9 100755 --- a/src/subscript/csv_stack/csv_stack.py +++ b/src/subscript/csv_stack/csv_stack.py @@ -319,7 +319,7 @@ def csv_stack( # the rows that emerged from the stacking. If you use the # 'all' pivottype, then you will get some NaN-values in the # MultiIndex columns that are intentional. - dframe[nostackcolumnnames] = dframe[nostackcolumnnames].fillna(method="ffill") + dframe[nostackcolumnnames] = dframe[nostackcolumnnames].ffill() dframe = dframe.reset_index() diff --git a/src/subscript/fmuobs/parsers.py b/src/subscript/fmuobs/parsers.py index 62e8d0e12..29527ead5 100644 --- a/src/subscript/fmuobs/parsers.py +++ b/src/subscript/fmuobs/parsers.py @@ -434,10 +434,10 @@ def compute_date_from_days(dframe: pd.DataFrame, starttime: Optional[str] = None dframe["DATE"] = np.nan start = pd.to_datetime(starttime) date_needed_rows = ~dframe["DAYS"].isna() & dframe["DATE"].isna() + dframe["DATE"] = pd.to_datetime(dframe["DATE"]) dframe.loc[date_needed_rows, "DATE"] = start + pd.to_timedelta( dframe.loc[date_needed_rows, "DAYS"], "d" ) - dframe["DATE"] = pd.to_datetime(dframe["DATE"]) if "DATE" in dframe: dframe["DATE"] = pd.to_datetime(dframe["DATE"]) return dframe diff --git a/src/subscript/fmuobs/writers.py b/src/subscript/fmuobs/writers.py index 9475dd140..321eee9f1 100644 --- a/src/subscript/fmuobs/writers.py +++ b/src/subscript/fmuobs/writers.py @@ -291,10 +291,13 @@ def convert_dframe_date_to_str(dframe: pd.DataFrame) -> pd.DataFrame: """ if "DATE" in dframe: dframe = dframe.copy() - dframe["DATE"] = dframe["DATE"].astype(str) - dframe["DATE"].replace("NaT", np.nan, inplace=True) - dframe["DATE"].replace("NaN", np.nan, inplace=True) - dframe["DATE"].replace("nan", np.nan, inplace=True) + dframe["DATE"] = ( + dframe["DATE"] + .astype(str) + .replace(["NaT", "NaN", "nan"], np.nan) + .infer_objects() + ) + return dframe diff --git a/src/subscript/interp_relperm/interp_relperm.py b/src/subscript/interp_relperm/interp_relperm.py index 45440ed50..03cca00e1 100755 --- a/src/subscript/interp_relperm/interp_relperm.py +++ b/src/subscript/interp_relperm/interp_relperm.py @@ -186,7 +186,7 @@ def make_wateroilgas(dframe: pd.DataFrame, delta_s: float) -> pyscal.WaterOilGas .sort_index() .dropna(how="all") .interpolate(method="index") - .fillna(method="bfill") + .bfill() .round(8) .drop_duplicates() .reset_index() @@ -197,7 +197,7 @@ def make_wateroilgas(dframe: pd.DataFrame, delta_s: float) -> pyscal.WaterOilGas .sort_index() .dropna(how="all") .interpolate(method="index") - .fillna(method="bfill") + .bfill() .round(8) .drop_duplicates() .reset_index() diff --git a/src/subscript/presentvalue/presentvalue.py b/src/subscript/presentvalue/presentvalue.py index 8f8793d1f..8d5f527c1 100755 --- a/src/subscript/presentvalue/presentvalue.py +++ b/src/subscript/presentvalue/presentvalue.py @@ -369,13 +369,13 @@ def calc_presentvalue_df( prodecon = pd.concat([summary_df, econ_df], axis=1, sort=True) prodecon[["oilprice", "gasprice", "usdtonok", "discountrate"]] = prodecon[ ["oilprice", "gasprice", "usdtonok", "discountrate"] - ].fillna(method="ffill") + ].ffill() # Avoid ffilling costs... # There could be situations where we need to bfill prices as well, # if the user provided a econtable prodecon[["oilprice", "gasprice", "usdtonok", "discountrate"]] = prodecon[ ["oilprice", "gasprice", "usdtonok", "discountrate"] - ].fillna(method="bfill") + ].bfill() prodecon.fillna(value=0, inplace=True) # Zero-pad other data (costs) prodecon["deltayears"] = prodecon.index - discountto diff --git a/src/subscript/prtvol2csv/prtvol2csv.py b/src/subscript/prtvol2csv/prtvol2csv.py index 038ae5306..3bdf94955 100644 --- a/src/subscript/prtvol2csv/prtvol2csv.py +++ b/src/subscript/prtvol2csv/prtvol2csv.py @@ -323,7 +323,11 @@ def prtvol2df( and add REGION and ZONE parameter. """ # Concatenate dataframes horizontally. Both are/must be indexed by FIPNUM: - volumes = pd.concat([simvolumes_df, resvolumes_df], axis=1).fillna(value=0.0) + volumes = ( + pd.concat([simvolumes_df, resvolumes_df], axis=1) + .apply(pd.to_numeric) + .fillna(value=0.0) + ) if fipmapper is not None: if fipmapper.has_fip2region: diff --git a/tests/test_welltest_dpds.py b/tests/test_welltest_dpds.py index d6391b680..dbd100ce8 100644 --- a/tests/test_welltest_dpds.py +++ b/tests/test_welltest_dpds.py @@ -70,8 +70,8 @@ def test_main(tmp_path, mocker): suptimew = pd.read_csv("spt.csv") # pylint: disable=no-member # (false positive) - assert suptimew.iloc[0][0] == pytest.approx(-9.87037983) - assert suptimew.iloc[-1][0] == pytest.approx(-0.65693308) + assert suptimew.iloc[0, 0] == pytest.approx(-9.87037983) + assert suptimew.iloc[-1, 0] == pytest.approx(-0.65693308) Path("welltest_output.csv").unlink() # test --genobs_resultfile