Python hypothesis.HealthCheck.all() Examples
The following are 21
code examples of hypothesis.HealthCheck.all().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hypothesis.HealthCheck
, or try the search function
.
Example #1
Source File: test_matrix_csr.py From lkpy with MIT License | 6 votes |
def test_csr_transpose(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) csc = csr.transpose() assert csc.nrows == csr.ncols assert csc.ncols == csr.nrows assert all(csc.rowptrs == [0, 1, 3, 4]) assert csc.colinds.max() == 3 assert csc.values.sum() == approx(vals.sum()) for r, c, v in zip(rows, cols, vals): row = csc.row(c) assert row[r] == v
Example #2
Source File: test_matrix_csr.py From lkpy with MIT License | 6 votes |
def test_csr_transpose_coords(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) csc = csr.transpose(False) assert csc.nrows == csr.ncols assert csc.ncols == csr.nrows assert all(csc.rowptrs == [0, 1, 3, 4]) assert csc.colinds.max() == 3 assert csc.values is None for r, c, v in zip(rows, cols, vals): row = csc.row(c) assert row[r] == 1
Example #3
Source File: test_matrix_csr.py From lkpy with MIT License | 6 votes |
def test_csr_transpose_erow(): nrows = np.random.randint(10, 1000) ncols = np.random.randint(10, 500) mat = np.random.randn(nrows, ncols) mat[mat <= 0] = 0 mat[:, 0:1] = 0 smat = sps.csr_matrix(mat) csr = lm.CSR.from_scipy(smat) csrt = csr.transpose() assert csrt.nrows == ncols assert csrt.ncols == nrows s2 = csrt.to_scipy() smat = smat.T.tocsr() assert all(smat.indptr == csrt.rowptrs) assert np.all(s2.toarray() == smat.toarray())
Example #4
Source File: test_matrix_csr.py From lkpy with MIT License | 6 votes |
def test_csr_from_sps(copy): # initialize sparse matrix mat = np.random.randn(10, 5) mat[mat <= 0] = 0 smat = sps.csr_matrix(mat) # make sure it's sparse assert smat.nnz == np.sum(mat > 0) csr = lm.CSR.from_scipy(smat, copy=copy) assert csr.nnz == smat.nnz assert csr.nrows == smat.shape[0] assert csr.ncols == smat.shape[1] assert all(csr.rowptrs == smat.indptr) assert all(csr.colinds == smat.indices) assert all(csr.values == smat.data) assert isinstance(csr.rowptrs, np.ndarray) assert isinstance(csr.colinds, np.ndarray) assert isinstance(csr.values, np.ndarray)
Example #5
Source File: test_matrix_csr.py From lkpy with MIT License | 6 votes |
def test_csr_from_coo_novals(): for i in range(50): coords = np.random.choice(np.arange(50 * 100, dtype=np.int32), 1000, False) rows = np.mod(coords, 100, dtype=np.int32) cols = np.floor_divide(coords, 100, dtype=np.int32) csr = lm.CSR.from_coo(rows, cols, None, (100, 50)) assert csr.nrows == 100 assert csr.ncols == 50 assert csr.nnz == 1000 for i in range(100): sp = csr.rowptrs[i] ep = csr.rowptrs[i+1] assert ep - sp == np.sum(rows == i) points, = np.nonzero(rows == i) po = np.argsort(cols[points]) points = points[po] assert all(np.sort(csr.colinds[sp:ep]) == cols[points]) assert np.sum(csr.row(i)) == len(points)
Example #6
Source File: test_matrix_csr.py From lkpy with MIT License | 6 votes |
def test_csr_to_sps(): # initialize sparse matrix mat = np.random.randn(10, 5) mat[mat <= 0] = 0 # get COO smat = sps.coo_matrix(mat) # make sure it's sparse assert smat.nnz == np.sum(mat > 0) csr = lm.CSR.from_coo(smat.row, smat.col, smat.data, shape=smat.shape) assert csr.nnz == smat.nnz assert csr.nrows == smat.shape[0] assert csr.ncols == smat.shape[1] smat2 = csr.to_scipy() assert sps.isspmatrix(smat2) assert sps.isspmatrix_csr(smat2) for i in range(csr.nrows): assert smat2.indptr[i] == csr.rowptrs[i] assert smat2.indptr[i+1] == csr.rowptrs[i+1] sp = smat2.indptr[i] ep = smat2.indptr[i+1] assert all(smat2.indices[sp:ep] == csr.colinds[sp:ep]) assert all(smat2.data[sp:ep] == csr.values[sp:ep])
Example #7
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_from_coo_rand(): for i in range(100): coords = np.random.choice(np.arange(50 * 100, dtype=np.int32), 1000, False) rows = np.mod(coords, 100, dtype=np.int32) cols = np.floor_divide(coords, 100, dtype=np.int32) vals = np.random.randn(1000) csr = lm.CSR.from_coo(rows, cols, vals, (100, 50)) rowinds = csr.rowinds() assert csr.nrows == 100 assert csr.ncols == 50 assert csr.nnz == 1000 for i in range(100): sp = csr.rowptrs[i] ep = csr.rowptrs[i+1] assert ep - sp == np.sum(rows == i) points, = np.nonzero(rows == i) assert len(points) == ep - sp po = np.argsort(cols[points]) points = points[po] assert all(np.sort(csr.colinds[sp:ep]) == cols[points]) assert all(np.sort(csr.row_cs(i)) == cols[points]) assert all(csr.values[np.argsort(csr.colinds[sp:ep]) + sp] == vals[points]) assert all(rowinds[sp:ep] == i) row = np.zeros(50) row[cols[points]] = vals[points] assert np.sum(csr.row(i)) == approx(np.sum(vals[points])) assert all(csr.row(i) == row)
Example #8
Source File: test_from_schema.py From hypothesis-jsonschema with Mozilla Public License 2.0 | 5 votes |
def test_multiple_contains_behind_allof(value): # By placing *multiple* contains elements behind "allOf" we've disabled the # mixed-generation logic, and so we can't generate any valid instances at all. jsonschema.validate(value, ALLOF_CONTAINS)
Example #9
Source File: test_from_schema.py From hypothesis-jsonschema with Mozilla Public License 2.0 | 5 votes |
def test_invalid_schemas_raise(schema): """Trigger all the validation exceptions for full coverage.""" with pytest.raises(Exception): from_schema(schema).example()
Example #10
Source File: test_canonicalise.py From hypothesis-jsonschema with Mozilla Public License 2.0 | 5 votes |
def _canonicalises_to_equivalent_fixpoint(data): # This function isn't executed by pytest, only by FuzzBuzz - we want to parametrize # over schemas for differnt types there, but have to supply *all* args here. schema = data.draw(json_schemata(), label="schema") cc = canonicalish(schema) assert cc == canonicalish(cc) try: strat = from_schema(cc) except InvalidArgument: # e.g. array of unique {type: integers}, with too few allowed integers assume(False) instance = data.draw(JSON_STRATEGY | strat, label="instance") assert is_valid(instance, schema) == is_valid(instance, cc) jsonschema.validators.validator_for(schema).check_schema(schema)
Example #11
Source File: test_binary.py From pyranges with MIT License | 5 votes |
def test_k_nearest(gr, gr2, nearest_how, overlap, strandedness, ties): print("-----" * 20) # gr = gr.apply(lambda df: df.astype({"Start": np.int32, "End": np.int32})) # gr2 = gr2.apply(lambda df: df.astype({"Start": np.int32, "End": np.int32})) # print(gr) # print(gr2) nearest_command = "bedtools closest -k 2 {bedtools_how} {strand} {overlap} {ties} -a <(sort -k1,1 -k2,2n {f1}) -b <(sort -k1,1 -k2,2n {f2})" bedtools_result = run_bedtools(nearest_command, gr, gr2, strandedness, overlap, nearest_how, ties) bedtools_df = pd.read_csv( StringIO(bedtools_result), header=None, names="Chromosome Start End Strand Chromosome2 Distance".split(), usecols=[0, 1, 2, 5, 6, 12], sep="\t") bedtools_df.Distance = bedtools_df.Distance.abs() bedtools_df = bedtools_df[bedtools_df.Chromosome2 != "."] bedtools_df = bedtools_df.drop("Chromosome2", 1) # cannot test with k > 1 because bedtools algo has different syntax # cannot test keep_duplicates "all" or None/False properly, as the semantics is different for bedtools result = gr.k_nearest( gr2, k=2, strandedness=strandedness, overlap=overlap, how=nearest_how, ties=ties) # result = result.apply(lambda df: df.astype({"Start": np.int64, "End": np.int64, "Distance": np.int64})) if len(result): result.Distance = result.Distance.abs() print("bedtools " * 5) print(bedtools_df) print("result " * 5) print(result) compare_results_nearest(bedtools_df, result)
Example #12
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_pickle(csr): data = pickle.dumps(csr) csr2 = pickle.loads(data) assert csr2.nrows == csr.nrows assert csr2.ncols == csr.ncols assert csr2.nnz == csr.nnz assert all(csr2.rowptrs == csr.rowptrs) assert all(csr2.colinds == csr.colinds) if csr.values is not None: assert all(csr2.values == csr.values) else: assert csr2.values is None
Example #13
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_filter(csr): assume(not np.all(csr.values <= 0)) # we have to have at least one to retain csrf = csr.filter_nnzs(csr.values > 0) assert all(csrf.values > 0) assert csrf.nnz <= csr.nnz for i in range(csr.nrows): spo, epo = csr.row_extent(i) spf, epf = csrf.row_extent(i) assert epf - spf <= epo - spo d1 = csr.to_scipy().toarray() df = csrf.to_scipy().toarray() d1[d1 < 0] = 0 assert df == approx(d1)
Example #14
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_sparse_row(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) assert all(csr.row_cs(0) == np.array([1, 2], dtype=np.int32)) assert all(csr.row_cs(1) == np.array([0], dtype=np.int32)) assert all(csr.row_cs(2) == np.array([], dtype=np.int32)) assert all(csr.row_cs(3) == np.array([1], dtype=np.int32)) assert all(csr.row_vs(0) == np.array([0, 1], dtype=np.float_)) assert all(csr.row_vs(1) == np.array([2], dtype=np.float_)) assert all(csr.row_vs(2) == np.array([], dtype=np.float_)) assert all(csr.row_vs(3) == np.array([3], dtype=np.float_))
Example #15
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_row(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) + 1 csr = lm.CSR.from_coo(rows, cols, vals) assert all(csr.row(0) == np.array([0, 1, 2], dtype=np.float_)) assert all(csr.row(1) == np.array([3, 0, 0], dtype=np.float_)) assert all(csr.row(2) == np.array([0, 0, 0], dtype=np.float_)) assert all(csr.row(3) == np.array([0, 4, 0], dtype=np.float_))
Example #16
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_set_values_undersize(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) v2 = np.random.randn(3) with raises(ValueError): csr.values = v2 assert all(csr.values == vals)
Example #17
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_set_values_oversize(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) v2 = np.random.randn(6) csr.values = v2 assert all(csr.values == v2[:4])
Example #18
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_set_values(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) v2 = np.random.randn(4) csr.values = v2 assert all(csr.values == v2)
Example #19
Source File: test_matrix_csr.py From lkpy with MIT License | 5 votes |
def test_csr_rowinds(): rows = np.array([0, 0, 1, 3], dtype=np.int32) cols = np.array([1, 2, 0, 1], dtype=np.int32) vals = np.arange(4, dtype=np.float_) csr = lm.CSR.from_coo(rows, cols, vals) ris = csr.rowinds() assert all(ris == rows)
Example #20
Source File: test_do_not_error.py From pyranges with MIT License | 4 votes |
def test_three_in_a_row(gr, gr2, gr3, strandedness_chain, method_chain): s1, s2 = strandedness_chain f1, f2 = method_chain suffix_methods = ["nearest", "join"] if f1 in suffix_methods and f2 in suffix_methods: m1 = getattr(gr, f1) gr2 = m1(gr2, strandedness=s1) if len(gr2) > 0: assert gr2.Start.dtype == np.int64 assert (gr2.Start >= 0).all() and (gr2.End >= 0).all() m2 = getattr(gr2, f2) gr3 = m2(gr3, strandedness=s2, suffix="_c") print(gr3) if len(gr3) > 0: assert gr3.Start.dtype == np.int64 assert (gr3.Start >= 0).all() and (gr3.End >= 0).all() else: m1 = getattr(gr, f1) gr2 = m1(gr2, strandedness=s1) if len(gr2) > 0: assert gr2.Start.dtype == np.int64 assert (gr2.Start >= 0).all() and (gr2.End >= 0).all() m2 = getattr(gr2, f2) gr3 = m2(gr3, strandedness=s2) print(gr3) if len(gr3) > 0: assert gr3.Start.dtype == np.int64 assert (gr3.Start >= 0).all() and (gr3.End >= 0).all() # @pytest.mark.bedtools # @pytest.mark.parametrize("strandedness_chain,method_chain", # product(strandedness_chain, method_chain)) # @settings( # max_examples=max_examples, # deadline=deadline, # suppress_health_check=HealthCheck.all()) # @given(gr=dfs_no_min(), gr2=dfs_no_min(), gr3=dfs_no_min()) # pylint: disable=no-value-for-parameter # def test_three_in_a_row(gr, gr2, gr3, strandedness_chain, method_chain): # s1, s2 = strandedness_chain # f1, f2 = method_chain # # print(s1, s2) # # print(f1, f2) # m1 = getattr(gr, f1) # gr2 = m1(gr2, strandedness=s1) # m2 = getattr(gr2, f2) # gr3 = m2(gr3, strandedness=s2)
Example #21
Source File: test_binary.py From pyranges with MIT License | 4 votes |
def test_coverage(gr, gr2, strandedness): print(gr.df) print(gr2.df) coverage_command = "bedtools coverage {strand} -a {f1} -b {f2}" bedtools_result = run_bedtools(coverage_command, gr, gr2, strandedness) bedtools_df = pd.read_csv( StringIO(bedtools_result), header=None, usecols=[0, 1, 2, 3, 4, 5, 6, 9], names= "Chromosome Start End Name Score Strand NumberOverlaps FractionOverlaps" .split(), dtype={"FractionOverlap": np.float}, sep="\t") result = gr.coverage(gr2, strandedness=strandedness) # assert len(result) > 0 assert np.all( bedtools_df.NumberOverlaps.values == result.NumberOverlaps.values) np.testing.assert_allclose( bedtools_df.FractionOverlaps, result.FractionOverlaps, atol=1e-5) # compare_results(bedtools_df, result) # @pytest.mark.bedtools # @pytest.mark.parametrize("strandedness", strandedness) # @settings( # max_examples=max_examples, # deadline=deadline, # suppress_health_check=HealthCheck.all()) # @given(gr=dfs_min(), gr2=dfs_min()) # pylint: disable=no-value-for-parameter # @reproduce_failure('4.15.0', b'AXicY2RgYGAEIzgAsRkZUfkMDAAA2AAI') # def test_no_intersect(gr, gr2, strandedness): # intersect_command = "bedtools intersect -v {strand} -a {f1} -b {f2}" # bedtools_result = run_bedtools(intersect_command, gr, gr2, strandedness) # bedtools_df = pd.read_csv( # StringIO(bedtools_result), # header=None, # names="Chromosome Start End Name Score Strand".split(), # sep="\t") # # bedtools bug: https://github.com/arq5x/bedtools2/issues/719 # result = gr.no_overlap(gr2, strandedness=strandedness) # from pydbg import dbg # dbg(result) # dbg(bedtools_df) # # result2 = gr.intersect(gr2, strandedness) # compare_results(bedtools_df, result)