class documentation

class TestClip:

View In Hierarchy

Undocumented

Method ​_generate​_data Undocumented
Method ​_generate​_data​_complex Undocumented
Method ​_generate​_flt​_data Undocumented
Method ​_generate​_int32​_data Undocumented
Method ​_generate​_int​_data Undocumented
Method ​_generate​_non​_native​_data Undocumented
Method ​_neg​_byteorder Undocumented
Method clip Undocumented
Method fastclip Undocumented
Method setup Undocumented
Method test​_array​_double Undocumented
Method test​_clip​_all​_none Undocumented
Method test​_clip​_complex Undocumented
Method test​_clip​_func​_takes​_out Undocumented
Method test​_clip​_inplace​_array Undocumented
Method test​_clip​_inplace​_simple Undocumented
Method test​_clip​_invalid​_casting Undocumented
Method test​_clip​_nan Undocumented
Method test​_clip​_non​_contig Undocumented
Method test​_clip​_problem​_cases Undocumented
Method test​_clip​_property A property-based test using Hypothesis.
Method test​_clip​_scalar​_nan​_propagation Undocumented
Method test​_clip​_value​_min​_max​_flip Undocumented
Method test​_clip​_with​_out​_array​_int32 Undocumented
Method test​_clip​_with​_out​_array​_outint32 Undocumented
Method test​_clip​_with​_out​_memory​_overlap Undocumented
Method test​_clip​_with​_out​_simple Undocumented
Method test​_clip​_with​_out​_simple2 Undocumented
Method test​_clip​_with​_out​_simple​_int32 Undocumented
Method test​_clip​_with​_out​_transposed Undocumented
Method test_​Na​T_propagation Undocumented
Method test​_noncontig​_inplace Undocumented
Method test​_object​_clip Undocumented
Method test​_ones​_pathological Undocumented
Method test​_simple​_complex Undocumented
Method test​_simple​_double Undocumented
Method test​_simple​_inplace​_01 Undocumented
Method test​_simple​_inplace​_02 Undocumented
Method test​_simple​_int Undocumented
Method test​_simple​_int32​_inout Undocumented
Method test​_simple​_int32​_out Undocumented
Method test​_simple​_int64​_inout Undocumented
Method test​_simple​_int64​_out Undocumented
Method test​_simple​_nonnative Undocumented
Method test​_simple​_out Undocumented
Method test​_type​_cast​_01 Undocumented
Method test​_type​_cast​_02 Undocumented
Method test​_type​_cast​_03 Undocumented
Method test​_type​_cast​_04 Undocumented
Method test​_type​_cast​_05 Undocumented
Method test​_type​_cast​_06 Undocumented
Method test​_type​_cast​_07 Undocumented
Method test​_type​_cast​_08 Undocumented
Method test​_type​_cast​_09 Undocumented
Method test​_type​_cast​_10 Undocumented
Method test​_type​_cast​_11 Undocumented
Method test​_type​_cast​_12 Undocumented
Instance Variable nc Undocumented
Instance Variable nr Undocumented
def _generate_data(self, n, m):

Undocumented

def _generate_data_complex(self, n, m):

Undocumented

def _generate_flt_data(self, n, m):

Undocumented

def _generate_int32_data(self, n, m):

Undocumented

def _generate_int_data(self, n, m):

Undocumented

def _generate_non_native_data(self, n, m):

Undocumented

def _neg_byteorder(self, a):

Undocumented

def clip(self, a, m, M, out=None):

Undocumented

def fastclip(self, a, m, M, out=None, casting=None):

Undocumented

def setup(self):

Undocumented

def test_array_double(self):

Undocumented

def test_clip_all_none(self):

Undocumented

def test_clip_complex(self):

Undocumented

def test_clip_func_takes_out(self):

Undocumented

def test_clip_inplace_array(self):

Undocumented

def test_clip_inplace_simple(self):

Undocumented

def test_clip_invalid_casting(self):

Undocumented

def test_clip_nan(self):

Undocumented

def test_clip_non_contig(self):

Undocumented

@pytest.mark.parametrize('arr, amin, amax, exp', [(np.zeros(10, dtype=np.int64), 0, -2**64+1, np.full(10, -2**64+1, dtype=object)), (np.zeros(10, dtype='m8')-1, 0, 0, np.zeros(10, dtype='m8'))])
def test_clip_problem_cases(self, arr, amin, amax, exp):

Undocumented

@given(data=st.data(), arr=hynp.arrays(dtype=hynp.integer_dtypes()|hynp.floating_dtypes(), shape=hynp.array_shapes()))
def test_clip_property(self, data, arr):

A property-based test using Hypothesis.

This aims for maximum generality: it could in principle generate any valid inputs to np.clip, and in practice generates much more varied inputs than human testers come up with.

Because many of the inputs have tricky dependencies - compatible dtypes and mutually-broadcastable shapes - we use st.data() strategy draw values inside the test function, from strategies we construct based on previous values. An alternative would be to define a custom strategy with @st.composite, but until we have duplicated code inline is fine.

That accounts for most of the function; the actual test is just three lines to calculate and compare actual vs expected results!

@pytest.mark.xfail(reason='no scalar nan propagation yet', raises=AssertionError, strict=True)
@pytest.mark.parametrize('arr, amin, amax', [(np.zeros(10, dtype=np.int64), np.array(np.nan), np.zeros(10, dtype=np.int32))])
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
def test_clip_scalar_nan_propagation(self, arr, amin, amax):

Undocumented

@pytest.mark.parametrize('amin, amax', [(1, 0), (1, np.zeros(10)), (np.ones(10), np.zeros(10))])
def test_clip_value_min_max_flip(self, amin, amax):

Undocumented

def test_clip_with_out_array_int32(self):

Undocumented

def test_clip_with_out_array_outint32(self):

Undocumented

def test_clip_with_out_memory_overlap(self):

Undocumented

def test_clip_with_out_simple(self):

Undocumented

def test_clip_with_out_simple2(self):

Undocumented

def test_clip_with_out_simple_int32(self):

Undocumented

def test_clip_with_out_transposed(self):

Undocumented

@pytest.mark.xfail(reason='propagation doesn\'t match spec')
@pytest.mark.parametrize('arr, amin, amax', [(np.array([1]*10, dtype='m8'), np.timedelta64('NaT'), np.zeros(10, dtype=np.int32))])
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
def test_NaT_propagation(self, arr, amin, amax):

Undocumented

def test_noncontig_inplace(self):

Undocumented

def test_object_clip(self):

Undocumented

@pytest.mark.parametrize('dtype', '?bhilqpBHILQPefdgFDGO')
def test_ones_pathological(self, dtype):

Undocumented

def test_simple_complex(self):

Undocumented

def test_simple_double(self):

Undocumented

def test_simple_inplace_01(self):

Undocumented

def test_simple_inplace_02(self):

Undocumented

def test_simple_int(self):

Undocumented

@pytest.mark.parametrize('casting', [None, 'unsafe'])
def test_simple_int32_inout(self, casting):

Undocumented

def test_simple_int32_out(self):

Undocumented

def test_simple_int64_inout(self):

Undocumented

def test_simple_int64_out(self):

Undocumented

def test_simple_nonnative(self):

Undocumented

def test_simple_out(self):

Undocumented

def test_type_cast_01(self):

Undocumented

def test_type_cast_02(self):

Undocumented

def test_type_cast_03(self):

Undocumented

def test_type_cast_04(self):

Undocumented

def test_type_cast_05(self):

Undocumented

def test_type_cast_06(self):

Undocumented

def test_type_cast_07(self):

Undocumented

def test_type_cast_08(self):

Undocumented

def test_type_cast_09(self):

Undocumented

def test_type_cast_10(self):

Undocumented

def test_type_cast_11(self):

Undocumented

def test_type_cast_12(self):

Undocumented

nc: int =

Undocumented

nr: int =

Undocumented