mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 07:08:12 +08:00
Autoformat python to fix lint errors (#1470)
* Autoformat python to fix lint errors * Fix lint errors not caught by black
This commit is contained in:
+1
-1
@@ -105,7 +105,7 @@ def get_data_adaptor(dataset=None):
|
|||||||
raise DatasetAccessError("Invalid dataset {dataset}")
|
raise DatasetAccessError("Invalid dataset {dataset}")
|
||||||
|
|
||||||
if datapath is None:
|
if datapath is None:
|
||||||
return common_rest.abort_and_log(HTTPStatus.BAD_REQUEST, f"Invalid dataset NONE", loglevel=logging.INFO)
|
return common_rest.abort_and_log(HTTPStatus.BAD_REQUEST, "Invalid dataset NONE", loglevel=logging.INFO)
|
||||||
|
|
||||||
cache_manager = current_app.matrix_data_cache_manager
|
cache_manager = current_app.matrix_data_cache_manager
|
||||||
return cache_manager.data_adaptor(datapath, config)
|
return cache_manager.data_adaptor(datapath, config)
|
||||||
|
|||||||
@@ -279,13 +279,13 @@ class AppConfig(object):
|
|||||||
if self.server__csp_directives is not None:
|
if self.server__csp_directives is not None:
|
||||||
for k, v in self.server__csp_directives.items():
|
for k, v in self.server__csp_directives.items():
|
||||||
if not isinstance(k, str):
|
if not isinstance(k, str):
|
||||||
raise ConfigurationError(f"CSP directive names must be a string.")
|
raise ConfigurationError("CSP directive names must be a string.")
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
for policy in v:
|
for policy in v:
|
||||||
if not isinstance(policy, str):
|
if not isinstance(policy, str):
|
||||||
raise ConfigurationError(f"CSP directive value must be a string or list of strings.")
|
raise ConfigurationError("CSP directive value must be a string or list of strings.")
|
||||||
elif not isinstance(v, str):
|
elif not isinstance(v, str):
|
||||||
raise ConfigurationError(f"CSP directive value must be a string or list of strings.")
|
raise ConfigurationError("CSP directive value must be a string or list of strings.")
|
||||||
|
|
||||||
# scripts can be string (filename) or dict (attributes). Convert string to dict.
|
# scripts can be string (filename) or dict (attributes). Convert string to dict.
|
||||||
scripts = []
|
scripts = []
|
||||||
@@ -476,8 +476,8 @@ class AppConfig(object):
|
|||||||
with self.matrix_data_cache_manager.data_adaptor(self.single_dataset__datapath, self) as data_adaptor:
|
with self.matrix_data_cache_manager.data_adaptor(self.single_dataset__datapath, self) as data_adaptor:
|
||||||
if self.diffexp__enable and data_adaptor.parameters.get("diffexp_may_be_slow", False):
|
if self.diffexp__enable and data_adaptor.parameters.get("diffexp_may_be_slow", False):
|
||||||
context["messagefn"](
|
context["messagefn"](
|
||||||
f"CAUTION: due to the size of your dataset, "
|
"CAUTION: due to the size of your dataset, "
|
||||||
f"running differential expression may take longer or fail."
|
"running differential expression may take longer or fail."
|
||||||
)
|
)
|
||||||
|
|
||||||
max_workers = self.diffexp__alg_cxg__max_workers
|
max_workers = self.diffexp__alg_cxg__max_workers
|
||||||
|
|||||||
@@ -183,13 +183,13 @@ class AnndataAdaptor(DataAdaptor):
|
|||||||
def _validate_and_initialize(self):
|
def _validate_and_initialize(self):
|
||||||
if anndata_version_is_pre_070() and self.config.adaptor__anndata_adaptor__backed:
|
if anndata_version_is_pre_070() and self.config.adaptor__anndata_adaptor__backed:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
f"Use of --backed mode with anndata versions older than 0.7 will have serious "
|
"Use of --backed mode with anndata versions older than 0.7 will have serious "
|
||||||
"performance issues. Please update to at least anndata 0.7 or later."
|
"performance issues. Please update to at least anndata 0.7 or later."
|
||||||
)
|
)
|
||||||
|
|
||||||
# var and obs column names must be unique
|
# var and obs column names must be unique
|
||||||
if not self.data.obs.columns.is_unique or not self.data.var.columns.is_unique:
|
if not self.data.obs.columns.is_unique or not self.data.var.columns.is_unique:
|
||||||
raise KeyError(f"All annotation column names must be unique.")
|
raise KeyError("All annotation column names must be unique.")
|
||||||
|
|
||||||
self._alias_annotation_names()
|
self._alias_annotation_names()
|
||||||
self._validate_data_types()
|
self._validate_data_types()
|
||||||
@@ -222,8 +222,8 @@ class AnndataAdaptor(DataAdaptor):
|
|||||||
X0 = self.data.X[0, 0:1]
|
X0 = self.data.X[0, 0:1]
|
||||||
if sparse.isspmatrix(X0) and not sparse.isspmatrix_csc(X0):
|
if sparse.isspmatrix(X0) and not sparse.isspmatrix_csc(X0):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
f"Anndata data matrix is sparse, but not a CSC (columnar) matrix. "
|
"Anndata data matrix is sparse, but not a CSC (columnar) matrix. "
|
||||||
f"Performance may be improved by using CSC."
|
"Performance may be improved by using CSC."
|
||||||
)
|
)
|
||||||
if self.data.X.dtype != "float32":
|
if self.data.X.dtype != "float32":
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
@@ -295,7 +295,7 @@ class AnndataAdaptor(DataAdaptor):
|
|||||||
valid_layouts.append(layout)
|
valid_layouts.append(layout)
|
||||||
|
|
||||||
if len(valid_layouts) == 0:
|
if len(valid_layouts) == 0:
|
||||||
raise PrepareError(f"No valid layout data.")
|
raise PrepareError("No valid layout data.")
|
||||||
|
|
||||||
# cap layouts to MAX_LAYOUTS
|
# cap layouts to MAX_LAYOUTS
|
||||||
return layouts[0:MAX_LAYOUTS]
|
return layouts[0:MAX_LAYOUTS]
|
||||||
|
|||||||
@@ -230,18 +230,19 @@ class DataAdaptor(metaclass=ABCMeta):
|
|||||||
|
|
||||||
# all labels must have a name, which must be unique and not used in obs column names
|
# all labels must have a name, which must be unique and not used in obs column names
|
||||||
if not labels_df.columns.is_unique:
|
if not labels_df.columns.is_unique:
|
||||||
raise KeyError(f"All column names specified in user annotations must be unique.")
|
raise KeyError("All column names specified in user annotations must be unique.")
|
||||||
|
|
||||||
# the label index must be unique, and must have same values the anndata obs index
|
# the label index must be unique, and must have same values the anndata obs index
|
||||||
if not labels_df.index.is_unique:
|
if not labels_df.index.is_unique:
|
||||||
raise KeyError(f"All row index values specified in user annotations must be unique.")
|
raise KeyError("All row index values specified in user annotations must be unique.")
|
||||||
|
|
||||||
obs_columns = self.get_obs_columns()
|
obs_columns = self.get_obs_columns()
|
||||||
|
|
||||||
duplicate_columns = list(set(labels_df.columns) & set(obs_columns))
|
duplicate_columns = list(set(labels_df.columns) & set(obs_columns))
|
||||||
if len(duplicate_columns) > 0:
|
if len(duplicate_columns) > 0:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
f"Labels file may not contain column names which overlap " f"with h5ad obs columns {duplicate_columns}"
|
"Labels file may not contain column names which overlap "
|
||||||
|
f"with h5ad obs columns {duplicate_columns}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# labels must have same count as obs annotations
|
# labels must have same count as obs annotations
|
||||||
@@ -351,13 +352,13 @@ class DataAdaptor(metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
embeddings = self.get_embedding_names() if fields is None or len(fields) == 0 else fields
|
embeddings = self.get_embedding_names() if fields is None or len(fields) == 0 else fields
|
||||||
layout_data = []
|
layout_data = []
|
||||||
with ServerTiming.time(f"layout.query"):
|
with ServerTiming.time("layout.query"):
|
||||||
for ename in embeddings:
|
for ename in embeddings:
|
||||||
embedding = self.get_embedding_array(ename, 2)
|
embedding = self.get_embedding_array(ename, 2)
|
||||||
normalized_layout = DataAdaptor.normalize_embedding(embedding)
|
normalized_layout = DataAdaptor.normalize_embedding(embedding)
|
||||||
layout_data.append(pd.DataFrame(normalized_layout, columns=[f"{ename}_0", f"{ename}_1"]))
|
layout_data.append(pd.DataFrame(normalized_layout, columns=[f"{ename}_0", f"{ename}_1"]))
|
||||||
|
|
||||||
with ServerTiming.time(f"layout.encode"):
|
with ServerTiming.time("layout.encode"):
|
||||||
if layout_data:
|
if layout_data:
|
||||||
df = pd.concat(layout_data, axis=1, copy=False)
|
df = pd.concat(layout_data, axis=1, copy=False)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ class MatrixDataLoader(object):
|
|||||||
self.matrix_data_type = self.__matrix_data_type()
|
self.matrix_data_type = self.__matrix_data_type()
|
||||||
|
|
||||||
if not self.__matrix_data_type_allowed(app_config):
|
if not self.__matrix_data_type_allowed(app_config):
|
||||||
raise DatasetAccessError(f"Dataset does not have an allowed type.")
|
raise DatasetAccessError("Dataset does not have an allowed type.")
|
||||||
|
|
||||||
if self.matrix_data_type == MatrixDataType.H5AD:
|
if self.matrix_data_type == MatrixDataType.H5AD:
|
||||||
from server.data_anndata.anndata_adaptor import AnndataAdaptor
|
from server.data_anndata.anndata_adaptor import AnndataAdaptor
|
||||||
@@ -272,7 +272,7 @@ class MatrixDataLoader(object):
|
|||||||
|
|
||||||
def pre_load_validation(self):
|
def pre_load_validation(self):
|
||||||
if self.matrix_data_type == MatrixDataType.UNKNOWN:
|
if self.matrix_data_type == MatrixDataType.UNKNOWN:
|
||||||
raise DatasetAccessError(f"Dataset does not have a recognized type: .h5ad or .cxg")
|
raise DatasetAccessError("Dataset does not have a recognized type: .h5ad or .cxg")
|
||||||
self.matrix_type.pre_load_validation(self.location)
|
self.matrix_type.pre_load_validation(self.location)
|
||||||
|
|
||||||
def file_size(self):
|
def file_size(self):
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ class CxgAdaptor(DataAdaptor):
|
|||||||
# function to get the embedding
|
# function to get the embedding
|
||||||
# this function to iterate through embeddings.
|
# this function to iterate through embeddings.
|
||||||
def get_embedding_names(self):
|
def get_embedding_names(self):
|
||||||
with ServerTiming.time(f"layout.lsuri"):
|
with ServerTiming.time("layout.lsuri"):
|
||||||
pemb = self.get_path("emb")
|
pemb = self.get_path("emb")
|
||||||
embeddings = [os.path.basename(p) for (p, t) in self.lsuri(pemb) if t == "array"]
|
embeddings = [os.path.basename(p) for (p, t) in self.lsuri(pemb) if t == "array"]
|
||||||
if len(embeddings) == 0:
|
if len(embeddings) == 0:
|
||||||
@@ -311,7 +311,7 @@ class CxgAdaptor(DataAdaptor):
|
|||||||
A = self.open_array(ax)
|
A = self.open_array(ax)
|
||||||
schema_hints = json.loads(A.meta["cxg_schema"]) if "cxg_schema" in A.meta else {}
|
schema_hints = json.loads(A.meta["cxg_schema"]) if "cxg_schema" in A.meta else {}
|
||||||
if type(schema_hints) is not dict:
|
if type(schema_hints) is not dict:
|
||||||
raise TypeError(f"Array schema was malformed.")
|
raise TypeError("Array schema was malformed.")
|
||||||
|
|
||||||
cols = []
|
cols = []
|
||||||
for attr in A.schema:
|
for attr in A.schema:
|
||||||
|
|||||||
+3
-3
@@ -156,7 +156,7 @@ try:
|
|||||||
|
|
||||||
dataroot = os.getenv("CXG_DATAROOT")
|
dataroot = os.getenv("CXG_DATAROOT")
|
||||||
if dataroot:
|
if dataroot:
|
||||||
logging.info(f"Configuration from CXG_DATAROOT")
|
logging.info("Configuration from CXG_DATAROOT")
|
||||||
app_config.update(multi_dataset__dataroot=dataroot)
|
app_config.update(multi_dataset__dataroot=dataroot)
|
||||||
|
|
||||||
secret_name = os.getenv("CXG_AWS_SECRET_NAME")
|
secret_name = os.getenv("CXG_AWS_SECRET_NAME")
|
||||||
@@ -171,7 +171,7 @@ try:
|
|||||||
if not secret_region_name:
|
if not secret_region_name:
|
||||||
secret_region_name = discover_s3_region_name(config_file)
|
secret_region_name = discover_s3_region_name(config_file)
|
||||||
if not secret_region_name:
|
if not secret_region_name:
|
||||||
logging.error(f"Could not determine the AWS Secret Manager region")
|
logging.error("Could not determine the AWS Secret Manager region")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
flask_secret_key = get_flask_secret_key(secret_region_name, secret_name)
|
flask_secret_key = get_flask_secret_key(secret_region_name, secret_name)
|
||||||
@@ -188,7 +188,7 @@ try:
|
|||||||
|
|
||||||
if not app_config.server__flask_secret_key:
|
if not app_config.server__flask_secret_key:
|
||||||
logging.critical(
|
logging.critical(
|
||||||
f"flask_secret_key is not provided. Either set in config file, CXG_SECRET_KEY environment variable, "
|
"flask_secret_key is not provided. Either set in config file, CXG_SECRET_KEY environment variable, "
|
||||||
"or in AWS Secret Manager"
|
"or in AWS Secret Manager"
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -29,16 +29,12 @@ def check(expected, custom):
|
|||||||
# cdict must only have exact requirements (==)
|
# cdict must only have exact requirements (==)
|
||||||
for cname, cspecs in cdict.items():
|
for cname, cspecs in cdict.items():
|
||||||
if len(cspecs) != 1 or cspecs[0][0] != "==":
|
if len(cspecs) != 1 or cspecs[0][0] != "==":
|
||||||
print(
|
print(f"Error, spec must be an exact requirement {custom}: {cname} {str(cspecs)}")
|
||||||
f"Error, spec must be an exact requirement {custom}: {cname} {str(cspecs)}"
|
|
||||||
)
|
|
||||||
okay = False
|
okay = False
|
||||||
|
|
||||||
for ename, especs in edict.items():
|
for ename, especs in edict.items():
|
||||||
if ename not in cdict:
|
if ename not in cdict:
|
||||||
print(
|
print(f"Error, missing requirement from {custom}: {ename} {str(especs)}")
|
||||||
f"Error, missing requirement from {custom}: {ename} {str(especs)}"
|
|
||||||
)
|
|
||||||
okay = False
|
okay = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -46,9 +42,7 @@ def check(expected, custom):
|
|||||||
for espec in especs:
|
for espec in especs:
|
||||||
rokay = check_version(cver, espec[0], Version(espec[1]))
|
rokay = check_version(cver, espec[0], Version(espec[1]))
|
||||||
if not rokay:
|
if not rokay:
|
||||||
print(
|
print(f"Error, failed requirement from {custom}: {ename} {espec}, {cver}")
|
||||||
f"Error, failed requirement from {custom}: {ename} {espec}, {cver}"
|
|
||||||
)
|
|
||||||
okay = False
|
okay = False
|
||||||
|
|
||||||
if okay:
|
if okay:
|
||||||
|
|||||||
@@ -185,14 +185,14 @@ class EndPoints(object):
|
|||||||
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
def test_data_mimetype_error(self):
|
def test_data_mimetype_error(self):
|
||||||
endpoint = f"data/var"
|
endpoint = "data/var"
|
||||||
header = {"Accept": "xxx"}
|
header = {"Accept": "xxx"}
|
||||||
url = f"{self.URL_BASE}{endpoint}"
|
url = f"{self.URL_BASE}{endpoint}"
|
||||||
result = self.session.put(url, headers=header)
|
result = self.session.put(url, headers=header)
|
||||||
self.assertEqual(result.status_code, HTTPStatus.NOT_ACCEPTABLE)
|
self.assertEqual(result.status_code, HTTPStatus.NOT_ACCEPTABLE)
|
||||||
|
|
||||||
def test_fbs_default(self):
|
def test_fbs_default(self):
|
||||||
endpoint = f"data/var"
|
endpoint = "data/var"
|
||||||
url = f"{self.URL_BASE}{endpoint}"
|
url = f"{self.URL_BASE}{endpoint}"
|
||||||
result = self.session.put(url)
|
result = self.session.put(url)
|
||||||
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
||||||
@@ -202,21 +202,21 @@ class EndPoints(object):
|
|||||||
self.assertEqual(result.headers["Content-Type"], "application/octet-stream")
|
self.assertEqual(result.headers["Content-Type"], "application/octet-stream")
|
||||||
|
|
||||||
def test_data_put_fbs(self):
|
def test_data_put_fbs(self):
|
||||||
endpoint = f"data/var"
|
endpoint = "data/var"
|
||||||
url = f"{self.URL_BASE}{endpoint}"
|
url = f"{self.URL_BASE}{endpoint}"
|
||||||
header = {"Accept": "application/octet-stream"}
|
header = {"Accept": "application/octet-stream"}
|
||||||
result = self.session.put(url, headers=header)
|
result = self.session.put(url, headers=header)
|
||||||
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
def test_data_get_fbs(self):
|
def test_data_get_fbs(self):
|
||||||
endpoint = f"data/var"
|
endpoint = "data/var"
|
||||||
url = f"{self.URL_BASE}{endpoint}"
|
url = f"{self.URL_BASE}{endpoint}"
|
||||||
header = {"Accept": "application/octet-stream"}
|
header = {"Accept": "application/octet-stream"}
|
||||||
result = self.session.get(url, headers=header)
|
result = self.session.get(url, headers=header)
|
||||||
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
def test_data_put_filter_fbs(self):
|
def test_data_put_filter_fbs(self):
|
||||||
endpoint = f"data/var"
|
endpoint = "data/var"
|
||||||
url = f"{self.URL_BASE}{endpoint}"
|
url = f"{self.URL_BASE}{endpoint}"
|
||||||
header = {"Accept": "application/octet-stream"}
|
header = {"Accept": "application/octet-stream"}
|
||||||
filter = {"filter": {"var": {"index": [0, 1, 4]}}}
|
filter = {"filter": {"var": {"index": [0, 1, 4]}}}
|
||||||
@@ -233,8 +233,8 @@ class EndPoints(object):
|
|||||||
|
|
||||||
def test_data_get_filter_fbs(self):
|
def test_data_get_filter_fbs(self):
|
||||||
index_col_name = self.schema["schema"]["annotations"]["var"]["index"]
|
index_col_name = self.schema["schema"]["annotations"]["var"]["index"]
|
||||||
|
endpoint = "data/var"
|
||||||
query = f"var:{index_col_name}=SIK1"
|
query = f"var:{index_col_name}=SIK1"
|
||||||
endpoint = f"data/var"
|
|
||||||
url = f"{self.URL_BASE}{endpoint}?{query}"
|
url = f"{self.URL_BASE}{endpoint}?{query}"
|
||||||
header = {"Accept": "application/octet-stream"}
|
header = {"Accept": "application/octet-stream"}
|
||||||
result = self.session.get(url, headers=header)
|
result = self.session.get(url, headers=header)
|
||||||
@@ -245,7 +245,7 @@ class EndPoints(object):
|
|||||||
self.assertEqual(df["n_cols"], 1)
|
self.assertEqual(df["n_cols"], 1)
|
||||||
|
|
||||||
def test_data_put_single_var(self):
|
def test_data_put_single_var(self):
|
||||||
endpoint = f"data/var"
|
endpoint = "data/var"
|
||||||
url = f"{self.URL_BASE}{endpoint}"
|
url = f"{self.URL_BASE}{endpoint}"
|
||||||
header = {"Accept": "application/octet-stream"}
|
header = {"Accept": "application/octet-stream"}
|
||||||
index_col_name = self.schema["schema"]["annotations"]["var"]["index"]
|
index_col_name = self.schema["schema"]["annotations"]["var"]["index"]
|
||||||
@@ -306,7 +306,7 @@ class EndPointsAnnotations(EndPoints):
|
|||||||
query = "annotation-collection-name=test_annotations"
|
query = "annotation-collection-name=test_annotations"
|
||||||
url = f"{self.URL_BASE}{endpoint}?{query}"
|
url = f"{self.URL_BASE}{endpoint}?{query}"
|
||||||
n_rows = self.data.get_shape()[0]
|
n_rows = self.data.get_shape()[0]
|
||||||
fbs = make_fbs({"cat_A": pd.Series(["label_A" for l in range(0, n_rows)], dtype="category")})
|
fbs = make_fbs({"cat_A": pd.Series(["label_A"] * n_rows, dtype="category")})
|
||||||
result = self.session.put(url, data=fbs)
|
result = self.session.put(url, data=fbs)
|
||||||
self.assertEqual(result.status_code, HTTPStatus.OK)
|
self.assertEqual(result.status_code, HTTPStatus.OK)
|
||||||
self.assertEqual(result.headers["Content-Type"], "application/json")
|
self.assertEqual(result.headers["Content-Type"], "application/json")
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
def test_error_checks(self):
|
def test_error_checks(self):
|
||||||
# verify that the expected errors are generated
|
# verify that the expected errors are generated
|
||||||
n_rows = self.data.get_shape()[0]
|
n_rows = self.data.get_shape()[0]
|
||||||
fbs_bad = make_fbs({"louvain": pd.Series(["undefined" for l in range(0, n_rows)], dtype="category")})
|
fbs_bad = make_fbs({"louvain": pd.Series(["undefined"] * n_rows, dtype="category")})
|
||||||
|
|
||||||
# ensure we catch attempt to overwrite non-writable data
|
# ensure we catch attempt to overwrite non-writable data
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
@@ -38,8 +38,8 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
n_rows = self.data.get_shape()[0]
|
n_rows = self.data.get_shape()[0]
|
||||||
fbs = make_fbs(
|
fbs = make_fbs(
|
||||||
{
|
{
|
||||||
"cat_A": pd.Series(["label_A" for l in range(0, n_rows)], dtype="category"),
|
"cat_A": pd.Series(["label_A"] * n_rows, dtype="category"),
|
||||||
"cat_B": pd.Series(["label_B" for l in range(0, n_rows)], dtype="category"),
|
"cat_B": pd.Series(["label_B"] * n_rows, dtype="category"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
res = self.annotation_put_fbs(fbs)
|
res = self.annotation_put_fbs(fbs)
|
||||||
@@ -49,14 +49,14 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
self.assertEqual(df.shape, (n_rows, 2))
|
self.assertEqual(df.shape, (n_rows, 2))
|
||||||
self.assertEqual(set(df.columns), {"cat_A", "cat_B"})
|
self.assertEqual(set(df.columns), {"cat_A", "cat_B"})
|
||||||
self.assertTrue(self.data.original_obs_index.equals(df.index))
|
self.assertTrue(self.data.original_obs_index.equals(df.index))
|
||||||
self.assertTrue(np.all(df["cat_A"] == ["label_A" for l in range(0, n_rows)]))
|
self.assertTrue(np.all(df["cat_A"] == ["label_A"] * n_rows))
|
||||||
self.assertTrue(np.all(df["cat_B"] == ["label_B" for l in range(0, n_rows)]))
|
self.assertTrue(np.all(df["cat_B"] == ["label_B"] * n_rows))
|
||||||
|
|
||||||
# verify complete overwrite on second attempt, AND rotation occurs
|
# verify complete overwrite on second attempt, AND rotation occurs
|
||||||
fbs = make_fbs(
|
fbs = make_fbs(
|
||||||
{
|
{
|
||||||
"cat_A": pd.Series(["label_A1" for l in range(0, n_rows)], dtype="category"),
|
"cat_A": pd.Series(["label_A1"] * n_rows, dtype="category"),
|
||||||
"cat_C": pd.Series(["label_C" for l in range(0, n_rows)], dtype="category"),
|
"cat_C": pd.Series(["label_C"] * n_rows, dtype="category"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
res = self.annotation_put_fbs(fbs)
|
res = self.annotation_put_fbs(fbs)
|
||||||
@@ -64,8 +64,8 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
self.assertTrue(path.exists(self.annotations.output_file))
|
self.assertTrue(path.exists(self.annotations.output_file))
|
||||||
df = pd.read_csv(self.annotations.output_file, index_col=0, header=0, comment="#")
|
df = pd.read_csv(self.annotations.output_file, index_col=0, header=0, comment="#")
|
||||||
self.assertEqual(set(df.columns), {"cat_A", "cat_C"})
|
self.assertEqual(set(df.columns), {"cat_A", "cat_C"})
|
||||||
self.assertTrue(np.all(df["cat_A"] == ["label_A1" for l in range(0, n_rows)]))
|
self.assertTrue(np.all(df["cat_A"] == ["label_A1"] * n_rows))
|
||||||
self.assertTrue(np.all(df["cat_C"] == ["label_C" for l in range(0, n_rows)]))
|
self.assertTrue(np.all(df["cat_C"] == ["label_C"] * n_rows))
|
||||||
|
|
||||||
# rotation
|
# rotation
|
||||||
name, ext = path.splitext(self.annotations.output_file)
|
name, ext = path.splitext(self.annotations.output_file)
|
||||||
@@ -79,8 +79,8 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
n_rows = self.data.get_shape()[0]
|
n_rows = self.data.get_shape()[0]
|
||||||
fbs = make_fbs(
|
fbs = make_fbs(
|
||||||
{
|
{
|
||||||
"cat_A": pd.Series(["label_A" for l in range(0, n_rows)], dtype="category"),
|
"cat_A": pd.Series(["label_A"] * n_rows, dtype="category"),
|
||||||
"cat_B": pd.Series(["label_B" for l in range(0, n_rows)], dtype="category"),
|
"cat_B": pd.Series(["label_B"] * n_rows, dtype="category"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for i in range(0, 11):
|
for i in range(0, 11):
|
||||||
@@ -100,8 +100,8 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
n_rows = self.data.get_shape()[0]
|
n_rows = self.data.get_shape()[0]
|
||||||
fbs = make_fbs(
|
fbs = make_fbs(
|
||||||
{
|
{
|
||||||
"cat_A": pd.Series(["label_A" for l in range(0, n_rows)], dtype="category"),
|
"cat_A": pd.Series(["label_A"] * n_rows, dtype="category"),
|
||||||
"cat_B": pd.Series(["label_B" for l in range(0, n_rows)], dtype="category"),
|
"cat_B": pd.Series(["label_B"] * n_rows, dtype="category"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -123,8 +123,8 @@ class WritableAnnotationTest(unittest.TestCase):
|
|||||||
[obs_index_col_name, "n_genes", "percent_mito", "n_counts", "louvain", "cat_A", "cat_B"],
|
[obs_index_col_name, "n_genes", "percent_mito", "n_counts", "louvain", "cat_A", "cat_B"],
|
||||||
)
|
)
|
||||||
col_idx = annotations["col_idx"]
|
col_idx = annotations["col_idx"]
|
||||||
self.assertEqual(annotations["columns"][col_idx.index("cat_A")], ["label_A" for l in range(0, n_rows)])
|
self.assertEqual(annotations["columns"][col_idx.index("cat_A")], ["label_A"] * n_rows)
|
||||||
self.assertEqual(annotations["columns"][col_idx.index("cat_B")], ["label_B" for l in range(0, n_rows)])
|
self.assertEqual(annotations["columns"][col_idx.index("cat_B")], ["label_B"] * n_rows)
|
||||||
|
|
||||||
# verify the schema was updated
|
# verify the schema was updated
|
||||||
all_col_schema = {c["name"]: c for c in schema["annotations"]["obs"]["columns"]}
|
all_col_schema = {c["name"]: c for c in schema["annotations"]["obs"]["columns"]}
|
||||||
|
|||||||
Reference in New Issue
Block a user