def handle_data(): json_request = request.get_json(cache=False) email, dataset = get_email_and_dataset(json_request) return json_response( data_processing.handle_data(dataset_api=dataset_api, dataset=dataset, embedding_list=json_request.get('embedding'), values=json_request.get('values'), stats=json_request.get('stats'), grouped_stats=json_request.get('groupedStats'), selection=json_request.get('selection')))
def test_no_binning(dataset_api, input_dataset, test_data, measures, dimensions, continuous_obs, basis): obsm_field = basis embedding_list = [dict(dimensions=2, name=basis)] values = dict(dimensions=dimensions, measures=measures + list(map(lambda x: "obs/" + x, continuous_obs))) results = handle_data(dataset_api=dataset_api, dataset=input_dataset, values=values, embedding_list=embedding_list) for key in measures: v = results["values"][key] # dict of indices, values if isinstance(v, dict): values = np.zeros(test_data.shape[0]) values[v["indices"]] = v["values"] else: values = v X = test_data[:, key].X if scipy.sparse.issparse(X): X = X.toarray() X = X.flatten() np.testing.assert_array_equal(values, X, err_msg=key) for key in dimensions: val = results["values"][key] if pd.api.types.is_categorical_dtype(test_data.obs[key]): val = pd.Categorical.from_codes(val["values"], val["categories"]) np.testing.assert_array_equal(val, test_data.obs[key].values, err_msg="obs field {}".format(key)) obsm = test_data.obsm[obsm_field] coords = results["embeddings"][0]["coordinates"] for i in range(obsm.shape[1]): np.testing.assert_array_equal(coords["{}_{}".format(basis, i + 1)], obsm[:, i], err_msg="obsm {}".format(key))