Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
brivas
mdf_reader
Commits
73596b88
Commit
73596b88
authored
5 years ago
by
Irene Perez Gonzalez
Browse files
Options
Download
Email Patches
Plain Diff
Changes following use of pandas nullable integers
parent
6b4baf21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
18 deletions
+7
-18
common/decoders.py
common/decoders.py
+7
-18
No files found.
common/decoders.py
View file @
73596b88
import
numpy
as
np
import
pandas
as
pd
import
string
from
..
import
properties
...
...
@@ -60,28 +61,16 @@ class df_decoders():
self
.
dtype
=
dtype
if
dtype
in
properties
.
numeric_types
else
'object'
def
signed_overpunch
(
self
,
data
):
decoded_numeric
=
np
.
vectorize
(
signed_overpunch_i
,
otypes
=
[
float
])(
data
)
try
:
return
decoded_numeric
.
astype
(
self
.
dtype
,
casting
=
'safe'
)
except
:
return
decoded_numeric
return
pd
.
Series
(
decoded_numeric
,
dtype
=
self
.
dtype
)
def
base36
(
self
,
data
):
# int(str(np.nan),36) ==> 30191
# Had to do the following because the astype() below did not seem to convert
# to object element-wise, but the full thing. As a result, str methods
# in converters from objects originating here were failing: the column
# was dtype = 'object', but the elements inside where 'int'....
# Checked that manually a seemed to be happening that way....
# Caution: int(str(np.nan),36) ==> 30191
if
self
.
dtype
==
'object'
:
base10
=
np
.
array
(
[
str
(
int
(
str
(
i
),
36
))
if
i
==
i
and
i
else
np
.
nan
for
i
in
data
]
)
base10
=
[
str
(
int
(
str
(
i
),
36
))
if
i
==
i
and
i
else
np
.
nan
for
i
in
data
]
else
:
base10
=
np
.
array
(
[
int
(
str
(
i
),
36
)
if
i
==
i
and
i
else
np
.
nan
for
i
in
data
]
)
base10
=
[
int
(
str
(
i
),
36
)
if
i
==
i
and
i
else
np
.
nan
for
i
in
data
]
try
:
return
base10
.
astype
(
self
.
dtype
,
casting
=
'safe'
)
except
:
return
base10
return
pd
.
Series
(
base10
,
dtype
=
self
.
dtype
)
decoders
=
dict
()
...
...
This diff is collapsed.
Click to expand it.
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