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
a3d1b08d
Commit
a3d1b08d
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: enhance output when table cannot be parsed
parent
52826846
No related branches found
No related tags found
1 merge request
!25
MAINT: enhance output when table cannot be parsed
Pipeline
#15823
passed
3 years ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/table_importer.py
+14
-8
14 additions, 8 deletions
src/caosadvancedtools/table_importer.py
with
14 additions
and
8 deletions
src/caosadvancedtools/table_importer.py
+
14
−
8
View file @
a3d1b08d
...
@@ -51,7 +51,7 @@ def assure_name_format(name):
...
@@ -51,7 +51,7 @@ def assure_name_format(name):
name
=
str
(
name
)
name
=
str
(
name
)
if
len
(
name
.
split
(
"
,
"
))
!=
2
:
if
len
(
name
.
split
(
"
,
"
))
!=
2
:
raise
ValueError
(
"
Nam
e field should be
'
LastName, FirstName
'
.
"
raise
ValueError
(
"
Th
e field
value
should be
'
LastName, FirstName
'
.
"
"
The supplied value was
'
{}
'
.
"
.
format
(
name
))
"
The supplied value was
'
{}
'
.
"
.
format
(
name
))
return
name
return
name
...
@@ -303,14 +303,20 @@ class TableImporter(object):
...
@@ -303,14 +303,20 @@ class TableImporter(object):
"""
"""
for
key
,
datatype
in
self
.
datatypes
.
items
():
for
key
,
datatype
in
self
.
datatypes
.
items
():
for
idx
,
val
in
df
.
loc
[
pd
.
notnull
(
df
.
loc
[:,
key
]),
key
].
iteritems
():
for
idx
,
val
in
df
.
loc
[
pd
.
notnull
(
df
.
loc
[:,
key
]),
key
].
iteritems
():
if
not
isinstance
(
val
,
datatype
):
if
not
isinstance
(
val
,
datatype
):
raise
DataInconsistencyError
(
msg
=
(
"
In row no. {rn} and column {c} of file
'
{fi}
'
the
"
"
In row no. {rn} and column
'
{c}
'
of file
'
{fi}
'
the
"
"
datatype was {was} but it should be
"
"
datatype was {was} but it should be
"
"
{expected}
"
.
format
(
rn
=
idx
,
c
=
key
,
fi
=
filename
,
"
{expected}
"
.
format
(
rn
=
idx
,
c
=
key
,
fi
=
filename
,
was
=
type
(
val
),
expected
=
datatype
)
was
=
str
(
type
(
val
)).
strip
(
"
<>
"
),
expected
=
str
(
datatype
).
strip
(
"
<>
"
))
)
)
logger
.
warning
(
msg
,
extra
=
{
'
identifier
'
:
filename
,
'
category
'
:
"
inconsistency
"
})
raise
DataInconsistencyError
(
msg
)
def
check_missing
(
self
,
df
,
filename
=
None
):
def
check_missing
(
self
,
df
,
filename
=
None
):
"""
"""
...
@@ -394,7 +400,7 @@ class XLSImporter(TableImporter):
...
@@ -394,7 +400,7 @@ class XLSImporter(TableImporter):
df
=
xls_file
.
parse
(
converters
=
self
.
converters
,
**
kwargs
)
df
=
xls_file
.
parse
(
converters
=
self
.
converters
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning
(
logger
.
warning
(
"
Cannot parse {}.
"
.
format
(
filename
),
"
Cannot parse {}.
\n
{}
"
.
format
(
filename
,
e
),
extra
=
{
'
identifier
'
:
str
(
filename
),
extra
=
{
'
identifier
'
:
str
(
filename
),
'
category
'
:
"
inconsistency
"
})
'
category
'
:
"
inconsistency
"
})
raise
DataInconsistencyError
(
*
e
.
args
)
raise
DataInconsistencyError
(
*
e
.
args
)
...
@@ -411,7 +417,7 @@ class CSVImporter(TableImporter):
...
@@ -411,7 +417,7 @@ class CSVImporter(TableImporter):
**
kwargs
)
**
kwargs
)
except
ValueError
as
ve
:
except
ValueError
as
ve
:
logger
.
warning
(
logger
.
warning
(
"
Cannot parse {}.
"
.
format
(
filename
),
"
Cannot parse {}.
\n
{}
"
.
format
(
filename
,
ve
),
extra
=
{
'
identifier
'
:
str
(
filename
),
extra
=
{
'
identifier
'
:
str
(
filename
),
'
category
'
:
"
inconsistency
"
})
'
category
'
:
"
inconsistency
"
})
raise
DataInconsistencyError
(
*
ve
.
args
)
raise
DataInconsistencyError
(
*
ve
.
args
)
...
@@ -428,7 +434,7 @@ class TSVImporter(TableImporter):
...
@@ -428,7 +434,7 @@ class TSVImporter(TableImporter):
**
kwargs
)
**
kwargs
)
except
ValueError
as
ve
:
except
ValueError
as
ve
:
logger
.
warning
(
logger
.
warning
(
"
Cannot parse {}.
"
.
format
(
filename
),
"
Cannot parse {}.
\n
{}
"
.
format
(
filename
,
ve
),
extra
=
{
'
identifier
'
:
str
(
filename
),
extra
=
{
'
identifier
'
:
str
(
filename
),
'
category
'
:
"
inconsistency
"
})
'
category
'
:
"
inconsistency
"
})
raise
DataInconsistencyError
(
*
ve
.
args
)
raise
DataInconsistencyError
(
*
ve
.
args
)
...
...
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