Skip to content

Commit

Permalink
sanity checks on create()
Browse files Browse the repository at this point in the history
  • Loading branch information
slinnarsson committed Sep 11, 2018
1 parent 5673070 commit 0ce0dfb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions loompy/loompy.py
Expand Up @@ -983,6 +983,20 @@ def create(filename: str, layers: Union[np.ndarray, Dict[str, np.ndarray], loomp
if "" not in layers:
raise ValueError("Data for default layer must be provided")

# Sanity checks
shape = layers[""].shape
if shape[0] == 0 or shape[1] == 0:
raise ValueError("Main matrix cannot be empty")
for name, layer in layers.items():
if layer.shape != shape:
raise ValueError(f"Layer '{name}' is not the same shape as the main matrix")
for name, ra in row_attrs.items():
if ra.shape[0] != shape[0]:
raise ValueError(f"Row attribute '{name}' is not the same length ({ra.shape[0]}) as number of rows in main matrix ({shape[0]})")
for name, ca in col_attrs.items():
if ca.shape[0] != shape[1]:
raise ValueError(f"Column attribute '{name}' is not the same length ({ca.shape[0]}) as number of columns in main matrix ({shape[1]})")

try:
with new(filename, file_attrs=file_attrs) as ds:
for key, vals in layers.items():
Expand Down

0 comments on commit 0ce0dfb

Please sign in to comment.