Skip to content

Commit

Permalink
Fixed int to float conversion in csv parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
smartin71 committed Aug 1, 2023
1 parent d668e22 commit e04511a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docker/compose/slycat-compose/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ configparser
future
routes
scipy
sklearn
npTDMS
scikit-learn
npTDMS==1.6.0
pandas
pysmb
natsort
10 changes: 7 additions & 3 deletions packages/slycat/pandas_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# common csv parsing code used by both slycat-web-server and slycat-web-client
# does not call slycat.web.server directly, instead returns any error messages
# error messages are returned as a list of {'type': 'warning', 'message': 'message'}
def parse_file(file):
# use file_name = True to pass a file name instead of a string with file contents
def parse_file(file, file_name=False):
"""
parses out a csv file into numpy array by column (data), the dimension meta data(dimensions),
and sets attributes (attributes)
Expand All @@ -29,7 +30,10 @@ def parse_file(file):

# load input file as pandas dataframe
try:
df = pd.read_csv(StringIO(file))
if file_name:
df = pd.read_csv(file)
else:
df = pd.read_csv(StringIO(file))

# return empty values if couldn't read file
except Exception as e:
Expand Down Expand Up @@ -59,7 +63,7 @@ def parse_file(file):
if df[header].dtype == "object":
data.append(df[header].values.astype('unicode'))
else:
data.append(df[header].values)
data.append(df[header].values.astype(float))

# check for empty headers (pandas replaced them with 'Unnamed: <Column #>')
empty_headers = []
Expand Down
7 changes: 3 additions & 4 deletions web-client/slycat/pandas_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
# common csv parsing code used by both slycat-web-server and slycat-web-client
# does not call slycat.web.server directly, instead returns any error messages
# error messages are returned as a list of {'type': 'warning', 'message': 'message'}
# use file_name=True if you are passing an actual file name, rather than a string
# containing the file data
# use file_name = True to pass a file name instead of a string with file contents
def parse_file(file, file_name=False):
"""
parses out a csv file into numpy array by column (data), the dimension meta data(dimensions),
Expand Down Expand Up @@ -64,8 +63,8 @@ def parse_file(file, file_name=False):
if df[header].dtype == "object":
data.append(df[header].values.astype('unicode'))
else:
data.append(df[header].values)

data.append(df[header].values.astype(float))
# check for empty headers (pandas replaced them with 'Unnamed: <Column #>')
empty_headers = []
headers = df.columns.values
Expand Down
7 changes: 1 addition & 6 deletions web-client/slycat/web/client/ps_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ def upload_model (arguments, attributes, dimensions, data, progress=True):

# Upload each column into the array.
for index in range(len(column_names)):

# make sure float are actually floats
if column_types[index] == 'float64':
values = [np.asarray(data[index]).astype(float)]
else:
values = [np.asarray(data[index])]
values = [np.asarray(data[index])]

# push to server
connection.put_model_arrayset_data(mid, "data-table", "0/%s/..." % index, values)
Expand Down

0 comments on commit e04511a

Please sign in to comment.