Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
2b138494
Verified
Commit
2b138494
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
REVEIW: changed name and signature of XLS_Importer
parent
0f46639d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Release 0.3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
src/caosadvancedtools/table_importer.py
+20
-19
20 additions, 19 deletions
src/caosadvancedtools/table_importer.py
unittests/test_table_importer.py
+4
-4
4 additions, 4 deletions
unittests/test_table_importer.py
with
26 additions
and
23 deletions
.gitignore
+
2
−
0
View file @
2b138494
...
...
@@ -4,3 +4,5 @@ __pycache__
*cache.db
*.egg-info
.docker/cert
version.py
.eggs/
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/table_importer.py
+
20
−
19
View file @
2b138494
...
...
@@ -47,9 +47,9 @@ def yes_no_converter(val):
"
Field should be
'
Yes
'
or
'
No
'
, but is
'
{}
'
.
"
.
format
(
val
))
class
XLS
_
Importer
(
object
):
class
XLSImporter
(
object
):
def
__init__
(
self
,
converters
,
obligatory_columns
=
None
,
unique_
column
s
=
None
):
def
__init__
(
self
,
converters
,
obligatory_columns
=
None
,
unique_
key
s
=
None
):
"""
converters: dict with column names as keys and converter functions as
...
...
@@ -65,7 +65,7 @@ class XLS_Importer(object):
self
.
sup
=
Suppressable
(
logger
=
logger
)
self
.
required_columns
=
list
(
converters
.
keys
())
self
.
obligatory_columns
=
[]
if
obligatory_columns
is
None
else
obligatory_columns
self
.
unique_
column
s
=
[]
if
unique_
column
s
is
None
else
unique_
column
s
self
.
unique_
key
s
=
[]
if
unique_
key
s
is
None
else
unique_
key
s
self
.
converters
=
converters
def
read_xls
(
self
,
filename
):
...
...
@@ -80,7 +80,7 @@ class XLS_Importer(object):
self
.
check_columns
(
df
,
filename
=
filename
)
df
=
self
.
check_missing
(
df
,
filename
=
filename
)
if
len
(
self
.
unique_
column
s
)
>
0
:
if
len
(
self
.
unique_
key
s
)
>
0
:
df
=
self
.
check_unique
(
df
,
filename
=
filename
)
return
df
...
...
@@ -96,22 +96,23 @@ class XLS_Importer(object):
df
=
df
.
copy
()
uniques
=
[]
subtable
=
df
[
list
(
self
.
unique_columns
)]
for
index
,
row
in
subtable
.
iterrows
():
element
=
tuple
(
row
)
if
element
in
uniques
:
errmssg
=
(
"
The {}. row contains the values
'
{}
'
.
\n
This value
"
"
combination should be unique, but was used in a previous
"
"
row in
\n
"
).
format
(
index
+
1
,
element
)
errmssg
+=
"
{}.
"
.
format
(
filename
)
if
filename
else
"
the file.
"
errmssg
+=
"
\n
This row will be ignored!
"
for
unique_columns
in
self
.
unique_keys
:
subtable
=
df
[
list
(
unique_columns
)]
for
index
,
row
in
subtable
.
iterrows
():
element
=
tuple
(
row
)
if
element
in
uniques
:
errmssg
=
(
"
The {}. row contains the values
'
{}
'
.
\n
This value
"
"
combination should be unique, but was used in a previous
"
"
row in
\n
"
).
format
(
index
+
1
,
element
)
errmssg
+=
"
{}.
"
.
format
(
filename
)
if
filename
else
"
the file.
"
errmssg
+=
"
\n
This row will be ignored!
"
self
.
sup
.
warning
(
errmssg
,
identifier
=
filename
,
category
=
"
inconsistency
"
)
df
=
df
.
drop
(
index
)
else
:
uniques
.
append
(
element
)
self
.
sup
.
warning
(
errmssg
,
identifier
=
filename
,
category
=
"
inconsistency
"
)
df
=
df
.
drop
(
index
)
else
:
uniques
.
append
(
element
)
return
df
...
...
This diff is collapsed.
Click to expand it.
unittests/test_table_importer.py
+
4
−
4
View file @
2b138494
...
...
@@ -22,7 +22,7 @@ from tempfile import NamedTemporaryFile
import
numpy
as
np
import
pandas
as
pd
from
caosadvancedtools.table_importer
import
(
XLS
_
Importer
,
name_converter
,
from
caosadvancedtools.table_importer
import
(
XLSImporter
,
name_converter
,
yes_no_converter
)
...
...
@@ -44,11 +44,11 @@ class ConverterTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
name_converter
,
"
Max Mustermann
"
)
class
XLS
_
ImporterTest
(
unittest
.
TestCase
):
class
XLSImporterTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
importer
=
XLS
_
Importer
(
self
.
importer
=
XLSImporter
(
converters
=
{
'
a
'
:
str
,
'
b
'
:
int
,
'
c
'
:
float
,
'
d
'
:
yes_no_converter
},
obligatory_columns
=
[
'
a
'
,
'
b
'
],
unique_
column
s
=
[
'
a
'
,
'
b
'
])
obligatory_columns
=
[
'
a
'
,
'
b
'
],
unique_
key
s
=
[
(
'
a
'
,
'
b
'
)
])
self
.
valid_df
=
pd
.
DataFrame
(
[[
'
a
'
,
1
,
2.0
,
'
yes
'
]],
columns
=
[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
])
...
...
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