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
61a31fff
Verified
Commit
61a31fff
authored
3 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
FIX: Don't cast float to int.
parent
d07196be
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!39
Release 0.4.0
,
!34
TableConverter now converts int to float and vice versa to match the desired dtype.
Pipeline
#19891
failed
3 years ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/table_importer.py
+5
-6
5 additions, 6 deletions
src/caosadvancedtools/table_importer.py
unittests/test_table_importer.py
+0
-2
0 additions, 2 deletions
unittests/test_table_importer.py
with
5 additions
and
8 deletions
src/caosadvancedtools/table_importer.py
+
5
−
6
View file @
61a31fff
...
...
@@ -312,8 +312,8 @@ class TableImporter():
.. note::
If columns are
float
, but should be
integer or vice versa
, this method converts the
respective columns
in place.
If columns are
integer
, but should be
float
, this method converts the
respective columns
in place.
Parameters
----------
...
...
@@ -323,14 +323,13 @@ class TableImporter():
"""
for
key
,
datatype
in
self
.
datatypes
.
items
():
# Check for castable numeric types first: We unconditionally cast
floa
t to
int and vice
#
versa
, because CaosDB does not have different sizes anyway.
# Check for castable numeric types first: We unconditionally cast
in
t to
the default
#
float
, because CaosDB does not have different sizes anyway.
col_dtype
=
df
.
dtypes
[
key
]
if
not
strict
and
not
np
.
issubdtype
(
col_dtype
,
datatype
):
issub
=
np
.
issubdtype
# These special cases should be fine.
if
((
issub
(
col_dtype
,
np
.
integer
)
and
issub
(
datatype
,
np
.
floating
))
or
(
issub
(
col_dtype
,
np
.
floating
)
and
issub
(
datatype
,
np
.
integer
))):
if
issub
(
col_dtype
,
np
.
integer
)
and
issub
(
datatype
,
np
.
floating
):
df
[
key
]
=
df
[
key
].
astype
(
datatype
)
# Now check each element
...
...
This diff is collapsed.
Click to expand it.
unittests/test_table_importer.py
+
0
−
2
View file @
61a31fff
...
...
@@ -218,12 +218,10 @@ class XLSImporterTest(TableImporterTest):
"
float_as_float
"
:
float
,
"
int_as_float
"
:
float
,
"
int_as_int
"
:
int
,
"
float_as_int
"
:
int
,
}
)
df
=
importer
.
read_xls
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"
data
"
,
"
datatypes.xlsx
"
))
assert
np
.
issubdtype
(
df
.
loc
[
0
,
"
int_as_float
"
],
float
)
assert
df
.
loc
[
1
,
"
float_as_int
"
]
==
6
# This is an acceptable rounding error.
class
CSVImporterTest
(
TableImporterTest
):
...
...
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