check_valid_dataframe
- postprocessinglib.utilities._helper_functions.check_valid_dataframe(observed: DataFrame, simulated: DataFrame)
Check if all observations or simulations are invalid and raise an exception/error if this is the case.
Invalid in this case refers to all values in the dataframe being NaN, negative or zero. It goes through both the observed and simulated seperately and makes sure that its values are not all Nan, negative or zero. If any of these conditions are not met, it raises an AllInvalidError specifying which condition was not met.
- Parameters:
observed (pd.DataFrame) – The observed dataframe being checked.
simulated (pd.DataFrame) – The simulated dataframe being checked.
- Raises:
AllInvalidError: – If all observations or all simulations are NaN or negative.
Example
>>> import numpy as np >>> import pandas as pd >>> from postprocessinglib.utilities import _helper_functions >>> # Create your index as an array >>> index = np.array([1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990]) >>> . >>> # Create a test dataframe >>> test_df = pd.DataFrame(data = data, columns = ("obs1", "sim1", "obs2", "sim2"), index = index) >>> obs = test_df.iloc[:, ::2] >>> sim = test_df.iloc[:, 1::2] >>> print(test_df) obs1 sim1 obs2 sim2 1981 NaN -inf -1 -inf 1982 NaN inf NaN NaN 1983 inf -inf NaN -inf 1984 -inf NaN inf NaN 1985 NaN -inf -inf inf 1986 -inf NaN NaN inf 1987 NaN -inf inf NaN 1988 inf -inf NaN NaN 1989 inf inf NaN -inf 1990 -inf inf NaN -inf >>> . >>> _helper_functions.check_valid_dataframe(observed=obs, simulated=sim) >>> # Error is raised due to all the observed values being invalid >>> # The error message is as follows: AllInvalidError: All observed values are invalid(negative)