Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nic
gridsource
Commits
2e8773e2
Commit
2e8773e2
authored
Nov 24, 2020
by
Nic
Browse files
[units][validation] make code more robust
parent
1ff3dbfd
Changes
1
Hide whitespace changes
Inline
Side-by-side
gridsource/validation.py
View file @
2e8773e2
...
...
@@ -424,27 +424,12 @@ class DataFrameSchematizer:
if
self
.
_is_units
:
# at this point, we still have df_num and df_nonnum
for
col
,
units
in
self
.
_target_units
.
copy
().
items
():
try
:
df_num
[
col
]
=
df_num
[
col
].
pint
.
to
(
units
)
except
KeyError
:
# no units specified in source file"
pass
except
:
# maybe a string where a number is expected...
# let's investigate it for a better user feedback
df
[
col
]
=
pd
.
Series
(
initial_without_urow
[
col
].
values
,
dtype
=
"pint[ ]"
,
index
=
initial_without_urow
.
index
,
)
self
.
_target_units
[
col
]
=
""
# .pop(col)
self
.
_source_units
[
col
]
=
""
# .pop(col)
early_report
[(
col
,
None
)].
append
(
"unable to convert this column"
)
df_num
=
df_num
.
pint
.
dequantify
()
df
=
pd
.
concat
((
df_num
,
df_nonnum
),
axis
=
1
)
# reorder columns as initially
df
.
columns
=
[
t
[
0
]
for
t
in
df
.
columns
.
tolist
()]
# restrict to level 0
if
col
not
in
df_num
.
columns
:
continue
df_num
[
col
]
=
df_num
[
col
].
pint
.
to
(
units
)
df
=
pd
.
concat
((
df_num
.
pint
.
dequantify
(),
df_nonnum
),
axis
=
1
)
# re-arrange columns: restrict to level 0 and reorder as initially
df
.
columns
=
[
t
[
0
]
for
t
in
df
.
columns
.
tolist
()]
df
=
df
[[
c
for
c
in
initial_without_urow
.
columns
]]
# =====================================================================
# fill empty values as requested by schema
...
...
Write
Preview
Markdown
is supported
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