Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RSE 23 Group Assignment Shervud Pitawanik Franz
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Niklas Franz
RSE 23 Group Assignment Shervud Pitawanik Franz
Commits
d06c035e
Commit
d06c035e
authored
1 year ago
by
Sortofamudkip
Browse files
Options
Downloads
Patches
Plain Diff
100% code coverage
parent
e46929fb
No related branches found
No related tags found
1 merge request
!12
Merge "Write tests" branch into master
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.coverage
+0
-0
0 additions, 0 deletions
.coverage
src/Dataset.py
+1
-1
1 addition, 1 deletion
src/Dataset.py
src/Plotter.py
+21
-20
21 additions, 20 deletions
src/Plotter.py
src/test_plotter.py
+66
-8
66 additions, 8 deletions
src/test_plotter.py
with
88 additions
and
29 deletions
.coverage
0 → 100644
+
0
−
0
View file @
d06c035e
File added
This diff is collapsed.
Click to expand it.
src/Dataset.py
+
1
−
1
View file @
d06c035e
...
...
@@ -255,7 +255,7 @@ class Dataset:
logging
.
error
(
"
parameter `colname` is not a string
"
)
raise
ValueError
(
f
"
{
colname
}
is not a string
"
)
return
self
.
dataframe
[
colname
].
explode
().
unique
()
return
self
.
dataframe
[
colname
].
unique
()
def
get_category_counts
(
self
,
colname
:
str
,
ascending
:
bool
=
None
...
...
This diff is collapsed.
Click to expand it.
src/Plotter.py
+
21
−
20
View file @
d06c035e
...
...
@@ -2,13 +2,14 @@ import numpy as np
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
import
seaborn
as
sns
from
Dataset
import
Dataset
import
src.
Dataset
import
logging
class
Plotter
:
def
__init__
(
self
,
dataset
:
Dataset
):
if
type
(
dataset
)
!=
Dataset
:
def
__init__
(
self
,
dataset
:
src
.
Dataset
.
Dataset
):
print
(
type
(
dataset
))
if
type
(
dataset
)
!=
src
.
Dataset
.
Dataset
:
logging
.
error
(
"
dataset parameter is not of type Dataset
"
)
raise
ValueError
(
f
"
{
dataset
}
is not of type Dataset
"
)
...
...
@@ -237,20 +238,20 @@ class Plotter:
self
.
customize_plot
(
fig
,
ax
,
styling_params
)
ax
.
scatter
(
self
.
df
[
target1
],
self
.
df
[
target2
])
def
distribution_plot
(
self
,
target
:
str
):
"""
distribution_plot _summary_
Args:
target (str): _description_
Returns:
None
"""
grouped_data
=
self
.
df
.
groupby
(
target
).
size
()
sorted_data
=
grouped_data
.
sort_values
(
ascending
=
True
)
plt
.
barh
(
sorted_data
.
index
,
sorted_data
.
values
,
data
=
sorted_data
)
print
(
grouped_data
.
sort_values
(
ascending
=
False
))
plt
.
xlabel
(
"
Size
"
)
plt
.
ylabel
(
target
)
plt
.
title
(
f
"
Distribution of
{
target
}
"
)
#
def distribution_plot(self, target: str):
#
"""
#
distribution_plot _summary_
#
Args:
#
target (str): _description_
#
Returns:
#
None
#
"""
#
grouped_data = self.df.groupby(target).size()
#
sorted_data = grouped_data.sort_values(ascending=True)
#
plt.barh(sorted_data.index, sorted_data.values, data=sorted_data)
#
print(grouped_data.sort_values(ascending=False))
#
plt.xlabel("Size")
#
plt.ylabel(target)
#
plt.title(f"Distribution of {target}")
This diff is collapsed.
Click to expand it.
src/test_plotter.py
+
66
−
8
View file @
d06c035e
from
pathlib
import
Path
from
Dataset
import
Dataset
import
src.
Dataset
from
Plotter
import
Plotter
import
pandas
as
pd
...
...
@@ -11,18 +11,22 @@ this_file_dir = Path(__file__).parent
@pytest.fixture
def
the_plotter
()
->
Dataset
:
dataset
=
Dataset
(
str
(
this_file_dir
/
"
../data/GamingStudy_data.csv
"
))
def
the_plotter
()
->
src
.
Dataset
.
Dataset
:
dataset
=
src
.
Dataset
.
Dataset
(
str
(
this_file_dir
/
"
../data/GamingStudy_data.csv
"
)
)
plotter
=
Plotter
(
dataset
)
return
plotter
def
test_load_plotter
():
"""
Tests that the Plotter class can be loaded.
"""
dataset
=
Dataset
(
str
(
this_file_dir
/
"
../data/GamingStudy_data.csv
"
))
dataset
=
src
.
Dataset
.
Dataset
(
str
(
this_file_dir
/
"
../data/GamingStudy_data.csv
"
)
)
plotter
=
Plotter
(
dataset
)
assert
type
(
plotter
.
df
)
==
pd
.
DataFrame
assert
type
(
plotter
.
ds
)
==
Dataset
assert
type
(
plotter
.
ds
)
==
src
.
Dataset
.
Dataset
def
test_catch_colname_not_in_df
(
the_plotter
:
Plotter
):
...
...
@@ -38,10 +42,37 @@ def test_catch_target_not_string(the_plotter: Plotter):
with
pytest
.
raises
(
ValueError
):
the_plotter
.
distribution_plot
(
True
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_bar_chart
(
True
,
"
GAD_T
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_bar_chart
(
"
GAD_T
"
,
True
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_bar_chart
(
"
GAD_TT
"
,
"
GAD_T
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_bar_chart
(
"
GAD_T
"
,
"
GAD_TT
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_histplot
(
True
,
"
GAD_T
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_histplot
(
"
GAD_T
"
,
True
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_histplot
(
"
GAD_TT
"
,
"
GAD_T
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_categorical_histplot
(
"
GAD_T
"
,
"
GAD_TT
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_scatterplot
(
True
,
"
GAD_T
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_scatterplot
(
"
GAD_T
"
,
True
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_scatterplot
(
"
GAD_TT
"
,
"
GAD_T
"
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_scatterplot
(
"
GAD_T
"
,
"
GAD_TT
"
)
@pytest.mark.parametrize
(
"
param
"
,
[
True
,
None
,
"
notdict
"
,
6.4
,
pd
,
(
1
,),
Dataset
],
[
True
,
None
,
"
notdict
"
,
6.4
,
pd
,
(
1
,),
src
.
Dataset
.
Dataset
],
)
def
test_catch_styling_params_not_dict
(
the_plotter
:
Plotter
,
param
):
"""
Tests that functions that take styling_params correctly
...
...
@@ -52,15 +83,42 @@ def test_catch_styling_params_not_dict(the_plotter: Plotter, param):
the_plotter
.
plot_categorical_histplot
(
"
GAD_T
"
,
"
GAD_T
"
,
param
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
plot_scatterplot
(
"
GAD_T
"
,
"
GAD_T
"
,
param
)
with
pytest
.
raises
(
ValueError
):
the_plotter
.
distribution_plot
(
"
GAD_T
"
,
param
)
def
test_catch_plotter_init_not_Dataset
():
"""
Tests that the Plotter
'
s init actually takes a Dataset.
"""
"""
Tests that the Plotter
'
s init actually takes a
src.Dataset.
Dataset.
"""
with
pytest
.
raises
(
ValueError
):
p
=
Plotter
(
"
not-a-Dataset
"
)
p
=
Plotter
(
"
not-a-
src.Dataset.
Dataset
"
)
def
test_customize_plot
(
the_plotter
:
Plotter
):
fig
,
ax
=
plt
.
subplots
()
the_plotter
.
customize_plot
(
fig
,
ax
,
{
"
title
"
:
"
a
"
})
assert
True
def
test_distribution_plot
(
the_plotter
:
Plotter
):
the_plotter
.
distribution_plot
(
"
GAD_T
"
)
assert
True
def
test_plot_categorical_bar_chart
(
the_plotter
:
Plotter
):
the_plotter
.
plot_categorical_bar_chart
(
"
GAD_T
"
,
"
SWL_T
"
)
assert
True
def
test_plot_categorical_boxplot
(
the_plotter
:
Plotter
):
the_plotter
.
plot_categorical_boxplot
(
"
whyplay
"
,
"
SWL_T
"
)
assert
True
def
test_plot_categorical_histplot
(
the_plotter
:
Plotter
):
the_plotter
.
plot_categorical_histplot
(
"
whyplay
"
,
"
SWL_T
"
)
assert
True
def
test_plot_scatterplot
(
the_plotter
:
Plotter
):
the_plotter
.
plot_scatterplot
(
"
GAD_T
"
,
"
SWL_T
"
)
assert
True
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment