MCPcopy Index your code
hub / github.com/quantopian/zipline / test_compare_to_str

Method test_compare_to_str

tests/test_labelarray.py:61–110  ·  view source on GitHub ↗
(self,
                            compval,
                            shape,
                            array_astype,
                            missing_value)

Source from the content-addressed store, hash-verified

59 missing_value=('', 'a', 'not in the array', None),
60 )
61 def test_compare_to_str(self,
62 compval,
63 shape,
64 array_astype,
65 missing_value):
66
67 strs = self.strs.reshape(shape).astype(array_astype)
68 if missing_value is None:
69 # As of numpy 1.9.2, object array != None returns just False
70 # instead of an array, with a deprecation warning saying the
71 # behavior will change in the future. Work around that by just
72 # using the ufunc.
73 notmissing = np.not_equal(strs, missing_value)
74 else:
75 if not isinstance(missing_value, array_astype):
76 missing_value = array_astype(missing_value, 'utf-8')
77 notmissing = (strs != missing_value)
78
79 arr = LabelArray(strs, missing_value=missing_value)
80
81 if not isinstance(compval, array_astype):
82 compval = array_astype(compval, 'utf-8')
83
84 # arr.missing_value should behave like NaN.
85 check_arrays(
86 arr == compval,
87 (strs == compval) & notmissing,
88 )
89 check_arrays(
90 arr != compval,
91 (strs != compval) & notmissing,
92 )
93
94 np_startswith = np.vectorize(lambda elem: elem.startswith(compval))
95 check_arrays(
96 arr.startswith(compval),
97 np_startswith(strs) & notmissing,
98 )
99
100 np_endswith = np.vectorize(lambda elem: elem.endswith(compval))
101 check_arrays(
102 arr.endswith(compval),
103 np_endswith(strs) & notmissing,
104 )
105
106 np_contains = np.vectorize(lambda elem: compval in elem)
107 check_arrays(
108 arr.has_substring(compval),
109 np_contains(strs) & notmissing,
110 )
111
112 @parameter_space(
113 __fail_fast=True,

Callers

nothing calls this directly

Calls 6

startswithMethod · 0.95
endswithMethod · 0.95
has_substringMethod · 0.95
LabelArrayClass · 0.90
check_arraysFunction · 0.90
astypeMethod · 0.80

Tested by

no test coverage detected