Skip to content

Commit

Permalink
Bring linting up to repo standards
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sol committed Jan 12, 2024
1 parent 1aece02 commit 0cf4cf3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/subscript/fmuobs/fmuobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def fmuobs(
"Please verify the output file"
)
logger.debug("After all the hard work, what is returned is this %s", dframe)
dump_results(dframe, csv, yml, resinsight, ertobs, Path(inputfile).parent)
dump_results(dframe, csv, yml, resinsight, ertobs, PosixPath(inputfile).parent)


def dump_results(
Expand All @@ -372,7 +372,7 @@ def dump_results(
yamlfile: Optional[str] = None,
resinsightfile: Optional[str] = None,
ertfile: Optional[str] = None,
parent_dir: Optional[PosixPath] = Path("."),
parent_dir: PosixPath = PosixPath("."),
) -> None:
"""Dump dataframe with ERT observations to CSV and/or YML
format to disk. Writes to stdout if filenames are "-". Skips
Expand Down
19 changes: 9 additions & 10 deletions src/subscript/fmuobs/gen_obs_writers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Read contents from simple text files"""
import logging
import warnings
import re
import warnings
from datetime import datetime
from pathlib import Path, PosixPath
from subscript.fmuobs.util import (
ERT_ALT_DATE_FORMAT,
ERT_DATE_FORMAT,
ERT_ISO_DATE_FORMAT,
)
from pathlib import PosixPath
from typing import Optional, Union, List, Tuple

from subscript.fmuobs.util import ERT_DATE_FORMAT, ERT_ISO_DATE_FORMAT

LOGGER = logging.getLogger("gen_obs_writers")

Expand Down Expand Up @@ -77,7 +75,7 @@ def ensure_correct_well_info_format(info):
return info


def find_well_file_path(folder_path: PosixPath) -> PosixPath:
def find_well_file_path(folder_path: PosixPath) -> Optional[PosixPath]:
"""Find file with well information in folder
Args:
Expand Down Expand Up @@ -182,7 +180,7 @@ def add_extra_well_data_if_rft(dict_to_change: dict, parent_dir, obs_folders):
print("After modification dict is ", dict_to_change)


def attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict) -> dict:
def attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict):
"""Attach data from secondary file if it exists
Args:
Expand Down Expand Up @@ -210,7 +208,8 @@ def attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict) -


def dump_content_to_dict(
file_path: PosixPath, col_names: list = ("observations", "error")
file_path: PosixPath,
col_names: Union[List, Tuple] = ("observations", "error"),
) -> dict:
"""Read contents of file into list
Expand Down
4 changes: 2 additions & 2 deletions src/subscript/fmuobs/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def summary_df2obsdict(smry_df: pd.DataFrame) -> List[dict]:
return smry_obs_list


def general_df2obsdict(general_df: pd.DataFrame, parent_dir: PosixPath) -> List[dict]:
def general_df2obsdict(general_df: pd.DataFrame, parent_dir: PosixPath) -> dict:
"""Generate a dictionary structure suitable for yaml
for general observations in dataframe representation
Expand Down Expand Up @@ -405,7 +405,7 @@ def block_df2obsdict(block_df: pd.DataFrame) -> List[dict]:
return block_obs_list


def df2obsdict(obs_df: pd.DataFrame, parent_dir: PosixPath = Path(".")) -> dict:
def df2obsdict(obs_df: pd.DataFrame, parent_dir: PosixPath = PosixPath(".")) -> dict:
"""Generate a dictionary structure of all observations, this data structure
is designed to look good in yaml, and is supported by WebViz and
fmu-ensemble.
Expand Down
11 changes: 9 additions & 2 deletions tests/_common_fmuobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

import yaml

TEST_DATA = TEST_DATA = "testdata_fmuobs/"
Expand Down Expand Up @@ -74,10 +75,16 @@ def assert_equal_length(to_be_tested, correct, key):
if to_be_tested_len != correct_len:
if to_be_tested_len > correct_len:
diff_set = to_be_tested_set.difference(correct_set)
mess = f"{key}: Produced keys are {to_be_tested_len - correct_len} more than they should ({diff_set})"
mess = (
f"{key}: Produced keys are {to_be_tested_len - correct_len} "
f"more than they should ({diff_set})"
)
else:
diff_set = correct_set.difference(to_be_tested_set)
mess = f"{key}: Produced keys are {correct_len - to_be_tested_len} less than they should ({diff_set})"
mess = (
f"{key}: Produced keys are {correct_len - to_be_tested_len} "
f"less than they should ({diff_set})"
)
raise AssertionError(mess)


Expand Down
24 changes: 4 additions & 20 deletions tests/test_fmuobs_functions_4_general_obs_w_drogon.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Test functions with drogon data"""
import pandas as pd
import pytest
from subscript.fmuobs.parsers import ertobs2df

from subscript.fmuobs.writers import general_df2obsdict

from ._common_fmuobs import (
_find_observation_file,
_assert_compulsories_are_correct,
_compare_to_results_in_file,
_find_observation_file,
)


Expand Down Expand Up @@ -81,13 +82,6 @@ def _fix_drogon_full_file():
return _find_observation_file("drogon_wbhp_rft_wct_gor_tracer_4d_plt.obs")


# def test_ertobs2df(drogon_full_obs_file):
# input_str = drogon_full_obs_file.read_text()
# print(input_str)
# full_df = ertobs2df(input_str)
# print(full_df)


@pytest.mark.parametrize(
"fixture_name",
["ert-doc_df", "drogon_tracer_df", "drogon_seismic_df", "drogon_rft_df"],
Expand Down Expand Up @@ -117,16 +111,6 @@ def test_general_df2obsdict(fixture_name, drogon_full_obs_file, request):
stream.close()
_assert_compulsories_are_correct(results)
if fixture_name != "ert-doc_df":
# Comparison with file not done for ert-doc, the ert-doc file is for
# Comparison with file not done for ert-doc, the ert-doc file is
# not just for general_obs
_compare_to_results_in_file(results, correct_result_file, where)


def test_general_df2obsdict_rft(drogon_full_obs_file, request):
fixture_name = "drogon_rft_df"
results = general_df2obsdict(
request.getfixturevalue(fixture_name), drogon_full_obs_file.parent
)
# _assert_compulsories_are_correct(results)

# _compare_to_results_in_file(results, fixture_name)
11 changes: 4 additions & 7 deletions tests/test_fmuobs_gen_obs_writers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import re
"""Unit tests for gen_obs_writers"""
from pathlib import Path
from subscript.fmuobs import gen_obs_writers

import pytest

from subscript.fmuobs import gen_obs_writers

TEST_DATA = "testdata_fmuobs"
RFT_FOLDERS = ["drogon/rft/", "somewhere/completely/different/rft_ERT_use_MDadjusted/"]

Expand Down Expand Up @@ -118,8 +120,3 @@ def test_tidy_general_obs_keys():
"tracer_jungle",
"magic_seismic_data",
}


# def test_add_extra_well_data_if_rft(dict_to_change: dict, parent_dir):
# def test_attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict) -> dict:
# def test_dump_content_to_dict(
15 changes: 5 additions & 10 deletions tests/test_fmuobs_make_dictionaries.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import re
from pathlib import Path
import yaml
from subscript.fmuobs.fmuobs import autoparse_file, df2obsdict
from pandas import DataFrame
import pytest
from pandas import DataFrame

from subscript.fmuobs.fmuobs import autoparse_file, df2obsdict

from ._common_fmuobs import _find_observation_file

from ._common_fmuobs import (
_find_observation_file,
_assert_compulsories_are_correct,
_compare_to_results_in_file,
)

TEST_DATA = "testdata_fmuobs/"

Expand Down

0 comments on commit 0cf4cf3

Please sign in to comment.