Skip to content

Commit

Permalink
Lint tools (#192)
Browse files Browse the repository at this point in the history
* Run black and flake8 over tools as well

* Import scipy.sparse instead of scipy
  • Loading branch information
gsakkis authored Jun 24, 2022
1 parent a147249 commit b45b234
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
- name: Check Python Black Format
run: |
python -m pip install black
python -m black --check --diff .
python -m black --check --diff . tools/[a-z]*
- name: Check for unsorted / unformatted Python imports
run: |
python -m pip install isort
python -m isort --check --diff .
- name: Check Python style guide enforcement with flake8
run: |
python -m pip install flake8-bugbear
python -m flake8 .
python -m flake8 . tools/[a-z]*
# TODO
# - name: Check Clang-Format
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsc/annotation_matrix_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, List, Optional

import pandas as pd
import scipy
import scipy.sparse
import tiledb

import tiledbsc.util as util
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from typing import Dict, List, Optional

import scipy
import scipy.sparse
import tiledb

import tiledbsc.util as util
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsc/assay_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
import pandas as pd
import scipy
import scipy.sparse
import tiledb

import tiledbsc.util as util
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsc/uns_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np
import pandas as pd
import scipy
import scipy.sparse
import tiledb

import tiledbsc.util as util
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsc/uns_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import anndata as ad
import numpy as np
import pandas as pd
import scipy
import scipy.sparse
import tiledb

import tiledbsc.util as util
Expand Down
1 change: 0 additions & 1 deletion apis/python/src/tiledbsc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy
import pandas as pd
import scipy
import scipy.sparse
import tiledb

Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsc/util_ann.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import anndata as ad
import numpy as np
import pandas as pd
import scipy
import scipy.sparse

import tiledbsc.util as util

Expand Down
6 changes: 3 additions & 3 deletions apis/python/tests/test_type_diversity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
import pandas as pd
import pytest
import scipy.sparse
import tiledb
from scipy import sparse

import tiledbsc.io as io
from tiledbsc import SOMA
Expand Down Expand Up @@ -63,9 +63,9 @@ def test_from_anndata_X_type(tmp_path, X_dtype_name, X_encoding):
if X_encoding == "dense":
X = np.eye(n_obs, n_var, dtype=X_dtype)
elif X_encoding == "csc":
X = sparse.eye(n_obs, n_var, dtype=X_dtype).tocsc()
X = scipy.sparse.eye(n_obs, n_var, dtype=X_dtype).tocsc()
elif X_encoding == "csr":
X = sparse.eye(n_obs, n_var, dtype=X_dtype).tocsr()
X = scipy.sparse.eye(n_obs, n_var, dtype=X_dtype).tocsr()

adata = ad.AnnData(X=X, obs=obs, var=var, dtype=X.dtype)
assert adata.X.dtype == X_dtype # sanity
Expand Down
8 changes: 4 additions & 4 deletions apis/python/tools/ingestor
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ select `relative=True`. (This is the default.)

if args.relative is not None:
relative = args.relative[0]
if relative == 'true':
if relative == "true":
soma_options.member_uris_are_relative = True
elif relative == 'false':
elif relative == "false":
soma_options.member_uris_are_relative = False
elif relative == 'auto':
elif relative == "auto":
soma_options.member_uris_are_relative = None
else:
raise Exception(f"Internal coding error in {__file__}")
Expand Down Expand Up @@ -220,7 +220,7 @@ def ingest_one(
if output_path.startswith("s3://") or output_path.startswith(
"tiledb://"
):
raise (
raise Exception(
"--ifexists replace currently only is compatible with local-disk paths"
)
print(f"Already exists; replacing: {output_path}")
Expand Down
18 changes: 8 additions & 10 deletions apis/python/tools/peek-ann
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
#
# -- then you can inspect the anndata object.

import os
import sys

import anndata
import anndata as ad # so we can type it either way
import numpy
import numpy as np # so we can type it either way
import pandas
import pandas as pd # so we can type it either way
import scipy
import tiledb
import scipy # noqa: F401
import tiledb # noqa: F401

import tiledbsc
import tiledbsc.io

# module aliases
ad = anndata
np = numpy
pd = pandas

if len(sys.argv) == 1:
input_path = "anndata/pbmc-small.h5ad"
elif len(sys.argv) == 2:
Expand All @@ -30,10 +31,7 @@ else:
sys.exit(1)

ann = anndata.read_h5ad(input_path)


def decat(ann):
return tiledbsc.util_ann._decategoricalize(ann)
decat = tiledbsc.util_ann._decategoricalize


# Interact at the prompt now:
Expand Down
20 changes: 9 additions & 11 deletions apis/python/tools/peek-soco
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
#
# -- then you can inspect the SOMACollection object

import os
import sys
import time
from typing import Dict, List

import anndata
import anndata as ad # so we can type it either way
import numpy
import numpy as np # so we can type it either way
import pandas
import pandas as pd # so we can type it either way
import scipy
import tiledb
import scipy # noqa: F401
import tiledb # noqa: F401

import tiledbsc
import tiledbsc as t
import tiledbsc.io as io
import tiledbsc.io

# module aliases
ad = anndata
np = numpy
pd = pandas

if len(sys.argv) == 1:
soco_path = "soma-collection"
Expand All @@ -32,6 +30,6 @@ else:
print(f"{sys.argv[0]}: need just one soma-collection path.", file=sys.stderr)
sys.exit(1)

soco = t.SOMACollection(soco_path)
soco = tiledbsc.SOMACollection(soco_path)

# Interact at the Python prompt now
13 changes: 7 additions & 6 deletions apis/python/tools/peek-soma
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
# -- then you can inspect the soma object.

import sys
import time

import anndata
import anndata as ad # so we can type it either way
import numpy
import numpy as np # so we can type it either way
import pandas
import pandas as pd # so we can type it either way
import scipy
import tiledb
import scipy # noqa: F401
import tiledb # noqa: F401

import tiledbsc
import tiledbsc.io

# module aliases
ad = anndata
np = numpy
pd = pandas

if len(sys.argv) == 1:
input_path = "tiledb-data/pbmc-small"
# input_path = 'tiledb-data/pbmc3k_processed'
Expand Down
9 changes: 4 additions & 5 deletions apis/python/tools/populate-soco
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def main():
)
parser.add_argument(
"--relative",
help=
"""
help="""
* If `false` then the group will remember the absolute paths of each member array/subgroup. For
ingesting to TileDB Cloud, this is necessary.
Expand All @@ -72,11 +71,11 @@ select `relative=True`. (This is the default.)

if args.relative is not None:
relative = args.relative[0]
if relative == 'true':
if relative == "true":
soma_options.member_uris_are_relative = True
elif relative == 'false':
elif relative == "false":
soma_options.member_uris_are_relative = False
elif relative == 'auto':
elif relative == "auto":
soma_options.member_uris_are_relative = None
else:
raise Exception(f"Internal coding error in {__file__}")
Expand Down

0 comments on commit b45b234

Please sign in to comment.