Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SE211_CSV
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ktc53
SE211_CSV
Commits
d099343a
Commit
d099343a
authored
Jan 29, 2020
by
Kyle Cook
Browse files
Options
Downloads
Patches
Plain Diff
Added set val functionality and Intermission
parent
46856ace
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Csv_F.py
+17
-5
17 additions, 5 deletions
Csv_F.py
User_File.py
+30
-0
30 additions, 0 deletions
User_File.py
__pycache__/Csv_F.cpython-37.pyc
+0
-0
0 additions, 0 deletions
__pycache__/Csv_F.cpython-37.pyc
with
47 additions
and
5 deletions
Csv_F.py
+
17
−
5
View file @
d099343a
...
...
@@ -53,21 +53,33 @@ class Csv_F:
return
self
.
__csv_data
[
r_index
][
c_index
]
def
set_row
(
self
,
id
,
new_row
,
is_header
=
False
,
force
=
False
):
data_len
=
self
.
__get_width
()
index
=
self
.
get_index
(
id
,
is_header
,
is_row
=
True
)
data_len
=
self
.
get_width
()
new_data_len
=
len
(
new_row
)
if
new_data_len
!=
data_len
and
not
force
:
raise
Exception
(
'
New data length does not match target. Set force flag if required.
'
)
from
None
return
False
else
:
constraints
=
((
new_row
,
data_len
)
if
new_data_len
>=
data_len
else
(
self
.
get_row
(
id
,
is_header
),
new_data_len
))
for
i
,
j
in
enumerate
(
constraints
[
0
]):
return
None
# (new_row if new_data_len >= data_len else new_row[0:data_len])
if
new_data_len
>=
data_len
:
for
data
,
col
in
enumerate
(
self
.
__csv_data
[
index
]):
else
:
for
data
,
col
in
enumerate
(
new_row
):
def
set_col
(
self
,
id
,
new_col
,
is_header
=
False
,
force
=
False
):
return
None
def
set_val
(
self
,
new_val
,
r_id
,
c_id
,
r_is_header
=
False
,
c_is_header
=
False
):
if
type
(
new_val
)
in
[
int
,
float
,
str
,
bool
]:
r_index
=
self
.
get_index
(
r_id
,
r_is_header
,
is_row
=
True
)
c_index
=
self
.
get_index
(
c_id
,
c_is_header
)
self
.
__csv_data
[
r_index
][
c_index
]
=
new_val
return
True
else
:
raise
Exception
(
'
The value entered must be a singlton.
'
+
str
(
type
(
new_val
))
+
'
Not accepted.
'
)
from
None
return
False
def
get_row_headers
(
self
):
return
self
.
__row_headers
...
...
...
...
This diff is collapsed.
Click to expand it.
User_File.py
+
30
−
0
View file @
d099343a
...
...
@@ -54,5 +54,35 @@ class CSV_Testing(unittest.TestCase):
self
.
assertRaises
(
Exception
,
CSV2
.
get_val
,
'
R2
'
,
'
NA
'
,
r_is_header
=
True
,
c_is_header
=
True
)
self
.
assertRaises
(
Exception
,
CSV2
.
get_val
,
'
NA
'
,
'
C1
'
,
r_is_header
=
True
,
c_is_header
=
True
)
def
test_val_setting
(
self
):
CSV1
=
Csv_Man
.
load
(
'
test1.csv
'
,
has_r_headers
=
True
,
has_c_headers
=
True
)
CSV2
=
Csv_Man
.
load
(
'
test2.csv
'
,
has_r_headers
=
True
,
has_c_headers
=
True
,
r_delim
=
'
;
'
,
c_delim
=
'
:
'
)
self
.
assertEqual
(
CSV1
.
get_val
(
0
,
0
),
'
1
'
)
CSV1
.
set_val
(
'
Q
'
,
0
,
0
)
self
.
assertEqual
(
CSV1
.
get_val
(
0
,
0
),
'
Q
'
)
self
.
assertEqual
(
CSV2
.
get_val
(
'
R1
'
,
'
C3
'
,
r_is_header
=
True
,
c_is_header
=
True
),
'
3
'
)
CSV2
.
set_val
(
'
Q
'
,
'
R1
'
,
'
C3
'
,
r_is_header
=
True
,
c_is_header
=
True
)
self
.
assertEqual
(
CSV2
.
get_val
(
'
R1
'
,
'
C3
'
,
r_is_header
=
True
,
c_is_header
=
True
),
'
Q
'
)
def
test_val_error
(
self
):
CSV1
=
Csv_Man
.
load
(
'
test1.csv
'
,
has_r_headers
=
True
,
has_c_headers
=
True
)
CSV2
=
Csv_Man
.
load
(
'
test2.csv
'
,
has_r_headers
=
True
,
has_c_headers
=
True
,
r_delim
=
'
;
'
,
c_delim
=
'
:
'
)
self
.
assertEqual
(
CSV1
.
get_val
(
0
,
0
),
'
1
'
)
self
.
assertRaises
(
Exception
,
CSV1
.
set_val
,
[
'
Q
'
],
0
,
0
)
self
.
assertEqual
(
CSV1
.
get_val
(
0
,
0
),
'
1
'
)
self
.
assertEqual
(
CSV2
.
get_val
(
'
R1
'
,
'
C3
'
,
r_is_header
=
True
,
c_is_header
=
True
),
'
3
'
)
self
.
assertRaises
(
Exception
,
CSV1
.
set_val
,
[
'
Q
'
],
'
R1
'
,
'
C3
'
,
r_is_header
=
True
,
c_is_header
=
True
)
self
.
assertEqual
(
CSV2
.
get_val
(
'
R1
'
,
'
C3
'
,
r_is_header
=
True
,
c_is_header
=
True
),
'
3
'
)
def
test_row_set
(
self
):
CSV1
=
Csv_Man
.
load
(
'
test1.csv
'
,
has_r_headers
=
True
,
has_c_headers
=
True
)
CSV2
=
Csv_Man
.
load
(
'
test2.csv
'
,
has_r_headers
=
True
,
has_c_headers
=
True
,
r_delim
=
'
;
'
,
c_delim
=
'
:
'
)
CSV1
.
set_row
(
0
,
[
'
Q
'
,
'
Q
'
,
'
Q
'
])
if
__name__
==
'
__main__
'
:
unittest
.
main
(
verbosity
=
1
)
This diff is collapsed.
Click to expand it.
__pycache__/Csv_F.cpython-37.pyc
+
0
−
0
View file @
d099343a
No preview for this file type
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
sign in
to comment