Commit c8b6eaf2 authored by Niklas Selke's avatar Niklas Selke
Browse files

Made some changes to the 'check_data' function in 'input_checks.py'.

parent 925a9a5d
......@@ -74,29 +74,30 @@ def check_data(input_argument, alt_input_idx, alt_input_vals):
or alt_input_vals is None))):
return None, None
if isinstance(input_argument, (pd.DataFrame, pd.Series)):
if not isinstance(input_argument.index, pd.DatetimeIndex):
return None, None
index = pd.DatetimeIndex(input_argument.index, copy=True)
index = input_argument.index
if isinstance(input_argument, pd.Series):
values = input_argument.to_numpy(copy=True)
elif "value" in input_argument.columns:
values = input_argument["value"].to_numpy(copy=True)
elif "values" in input_argument.columns:
values = input_argument["values"].to_numpy(copy=True)
param_vals = input_argument.to_numpy()
elif "value" in input_argument.columns.to_numpy():
param_vals = input_argument["value"].to_numpy()
elif "values" in input_argument.columns.to_numpy():
param_vals = input_argument["values"].to_numpy()
elif input_argument.shape[1] > 0:
param_vals = input_argument.iloc[:, 0].to_numpy()
else:
values = input_argument.iloc[:, 0].to_numpy(copy=True)
elif (isinstance(alt_input_idx, pd.DatetimeIndex)
and isinstance(alt_input_vals, np.ndarray)):
index = pd.DatetimeIndex(alt_input_idx, copy=True)
values = np.array(alt_input_vals, copy=True)
return None, None
else:
index = alt_input_idx
param_vals = alt_input_vals
if not isinstance(index, pd.DatetimeIndex):
return None, None
if not isinstance(param_vals, np.ndarray) or param_vals.ndim != 1:
return None, None
if (index.dropna().empty or all(np.isnan(values))
or index.size != values.size):
if (index.dropna().empty or all(np.isnan(param_vals))
or index.size != param_vals.size):
return None, None
if not (np.issubdtype(values.dtype, np.floating)
or np.issubdtype(values.dtype, np.integer)):
if not (np.issubdtype(param_vals.dtype, np.floating)
or np.issubdtype(param_vals.dtype, np.integer)):
return None, None
if index.tz:
index = index.tz_localize(None)
return index, values
return index, param_vals
......@@ -92,4 +92,4 @@ def calculate_statistics(sampling, statistics, data=None, metadata=None,
"""
sampling_method = check_sampling(sampling)
stats_list = check_statistics(statistics)
idx, vals = check_data(data, datetimes, values)
datetime_index, parameter_values = check_data(data, datetimes, values)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment