Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
esde
toar-public
toarstats
Commits
c9ad31c4
Commit
c9ad31c4
authored
Oct 27, 2021
by
Niklas Selke
Browse files
Refactored the 'check_data' function in 'input_checks.py'. It now returns a data frame.
parent
b44c5acf
Changes
2
Hide whitespace changes
Inline
Side-by-side
toarstats/input_checks.py
View file @
c9ad31c4
"""Functions to check the given user inputs.
This module contains the following function:
This module contains the following function
s
:
check_sampling - check the given sampling argument
check_statistics - check the given statistics argument
check_data - check the given data argument
"""
import
numpy
as
np
...
...
@@ -56,46 +58,46 @@ def check_statistics(statistics_in):
return
statistics_out
def
check_data
(
input_argument
,
alt_input_idx
,
al
t_input_vals
):
def
check_data
(
data_in
,
datetimes_in
,
v
al
ues_in
):
"""Check the given data argument.
:param
input_argument
: the given argument
:param
alt_input_idx: the alternative input's index
:param al
t_input_vals: the alternative input's values
:param
data_in
: the given
data
argument
:param
datetimes_in: the given datetimes argument
:param
v
al
ues_in: the given values argument
:return: The processed argument
s
or None if there was a problem
with
the inpu
t
:return: The processed
data
argument or None if there was a problem
while processing the given data argumen
t
"""
if
(
(
input_argument
is
not
None
and
not
(
alt_input_idx
is
None
and
al
t_input_vals
is
None
))
or
(
input_argument
is
None
and
(
alt_input_idx
is
None
or
al
t_input_vals
is
None
)
))
:
return
None
,
None
if
isinstance
(
input_argument
,
(
pd
.
DataFrame
,
pd
.
Series
)):
index
=
input_argument
.
index
if
isinstance
(
input_argument
,
pd
.
Series
):
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
()
if
(
data_in
is
not
None
and
not
(
datetimes_in
is
None
and
v
al
ues_in
is
None
))
:
return
None
if
data_in
is
None
and
(
datetimes_in
is
None
or
v
al
ues_in
is
None
):
return
None
if
isinstance
(
data_in
,
(
pd
.
DataFrame
,
pd
.
Series
)):
index
_out
=
data_in
.
index
if
isinstance
(
data_in
,
pd
.
Series
):
values_out
=
data_in
.
to_numpy
()
elif
"value"
in
data_in
.
columns
.
to_numpy
():
values_out
=
data_in
[
"value"
].
to_numpy
()
elif
"values"
in
data_in
.
columns
.
to_numpy
():
values_out
=
data_in
[
"values"
].
to_numpy
()
elif
data_in
.
shape
[
1
]
>
0
:
values_out
=
data_in
.
iloc
[:,
0
].
to_numpy
()
else
:
return
None
,
None
values_out
=
np
.
array
([])
else
:
index
=
alt_input_idx
param_vals
=
al
t_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
(
param_vals
)
)
or
index
.
size
!=
param_vals
.
size
):
return
None
,
None
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
,
param_vals
index
_out
=
datetimes_in
values_out
=
v
al
ues_in
if
not
isinstance
(
index
_out
,
pd
.
DatetimeIndex
):
return
None
if
not
isinstance
(
values_out
,
np
.
ndarray
)
or
values_out
.
ndim
!=
1
:
return
None
if
not
(
np
.
issubdtype
(
values_out
.
dtype
,
np
.
floating
)
or
np
.
issubdtype
(
values_out
.
dtype
,
np
.
integer
)
):
return
None
if
(
index_out
.
dropna
().
empty
or
all
(
np
.
isnan
(
values_out
)
)
or
index_out
.
size
!=
values_out
.
size
):
return
None
if
index
_out
.
tz
:
index
_out
=
index
_out
.
tz_localize
(
None
)
return
pd
.
DataFrame
({
"values"
:
values_out
},
index
=
index_out
)
toarstats/interface.py
View file @
c9ad31c4
...
...
@@ -92,4 +92,4 @@ def calculate_statistics(sampling, statistics, data=None, metadata=None,
"""
sampling_method
=
check_sampling
(
sampling
)
stats_list
=
check_statistics
(
statistics
)
dat
etime_index
,
parameter_values
=
check_data
(
data
,
datetimes
,
values
)
dat
a_frame
=
check_data
(
data
,
datetimes
,
values
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment