Skip to content

Commit

Permalink
ReadStrategies cast dataframes to correct types
Browse files Browse the repository at this point in the history
  • Loading branch information
willu47 committed Oct 22, 2020
1 parent fd2685f commit e3eee87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/otoole/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ def _check_index(self, input_data: Dict):
"""
for name, df in input_data.items():
details = self.config[name]

dtypes = {}

for column in details["indices"] + ["VALUE"]:
if column == "VALUE":
datatype = details["dtype"]
dtypes["VALUE"] = datatype
else:
datatype = self.config[column]["dtype"]
dtypes[column] = datatype

df.astype(dtypes, copy=False)

try:
df.set_index(details["indices"], inplace=True)
except KeyError:
Expand Down
6 changes: 1 addition & 5 deletions src/otoole/preprocess/longify_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,10 @@ def check_datatypes(
)
if datatype == "int":
try:
narrow[column] = narrow[column].apply(_cast_to_int)
narrow[column] = narrow[column].apply(lambda x: int(x))
except ValueError as ex:
msg = "Unable to apply datatype for column {}: {}".format(
column, str(ex)
)
raise ValueError(msg)
return narrow.astype(dtypes)


def _cast_to_int(value):
return int(float(value))

0 comments on commit e3eee87

Please sign in to comment.