Skip to content
Permalink
Browse files

Merge pull request #514 from girder/fix-nan-transform

Fix transforms containing NaN's
  • Loading branch information
jbeezley committed Apr 23, 2020
2 parents c5a58b0 + 113f512 commit b9d9623daeb345f479903cb84ff46d9e87e433da
Showing with 11 additions and 9 deletions.
  1. +1 −5 viime/analyses.py
  2. +7 −2 viime/models.py
  3. +1 −0 viime/transformation.py
  4. +2 −2 viime/views.py
@@ -2,16 +2,12 @@
from itertools import combinations
from typing import Any, Dict, Optional

import numpy as np
import pandas as pd

from .models import clean
from .opencpu import opencpu_request


def clean(df: pd.DataFrame) -> pd.DataFrame:
return df.fillna('NaN').replace([np.Inf, -np.Inf], ['Inf', '-Inf'])


def wilcoxon_test(measurements: pd.DataFrame, groups: pd.Series,
log_transformed=False) -> Dict[str, Any]:
files = {
@@ -51,6 +51,11 @@
METADATA_TYPES = MetaDataTypes('categorical', 'numerical', 'ordinal')


def clean(df: pandas.DataFrame) -> pandas.DataFrame:
return df.fillna('NaN') \
.replace([numpy.Inf, -numpy.Inf], ['Inf', '-Inf'])


def _guess_table_structure(table):
# TODO: Implement this for real, this is just a dumb placeholder
rows = [TABLE_ROW_TYPES.INDEX] + [
@@ -384,7 +389,7 @@ def read_csv_file(self, data, **kwargs):

data['table'] = data['table'].to_csv(header=False, index=False)
if data.get('measurement_table') is not None:
data['measurement_table'] = data['measurement_table'].to_dict(
data['measurement_table'] = clean(data['measurement_table']).to_dict(
orient='split')
return data

@@ -862,7 +867,7 @@ def serialize_tables(self, data, **kwargs):
# don't transfer columns or index depending on the type
def convert(attr, *drop_columns):
if attr in data:
converted = data[attr].to_dict(orient='split')
converted = clean(data[attr]).to_dict(orient='split')
for drop_column in drop_columns:
if drop_column in converted:
del converted[drop_column]
@@ -4,6 +4,7 @@


def transform(method, table):
table = table.astype(np.float64)
if method is None:
table = table
elif method == 'log10':
@@ -13,7 +13,7 @@
from viime import opencpu, samples
from viime.analyses import anova_test, hierarchical_clustering, pairwise_correlation, wilcoxon_test
from viime.imputation import IMPUTE_MCAR_METHODS, IMPUTE_MNAR_METHODS
from viime.models import AXIS_NAME_TYPES, CSVFile, CSVFileSchema, db, \
from viime.models import AXIS_NAME_TYPES, clean, CSVFile, CSVFileSchema, db, \
GroupLevelSchema, ModifyLabelListSchema, \
TABLE_COLUMN_TYPES, TABLE_ROW_TYPES, \
TableColumn, TableColumnSchema, TableRow, \
@@ -700,7 +700,7 @@ def _get_pca_data(validated_table):
# insert per row label metadata information
labels = validated_table.sample_metadata
groups = validated_table.groups
data['labels'] = pandas.concat([groups, labels], axis=1).to_dict('list')
data['labels'] = clean(pandas.concat([groups, labels], axis=1)).to_dict('list')
data['rows'] = table.index.tolist()

return data

0 comments on commit b9d9623

Please sign in to comment.
You can’t perform that action at this time.