def test_ufunc_logical_skipna_d(self) -> None: a1 = np.array(['2018-01-01', '2018-02-01'], dtype=np.datetime64) post1 = _ufunc_logical_skipna(a1, np.all, skipna=True) self.assertTrue(post1) a2 = np.array(['2018-01-01', '2018-02-01', None], dtype=np.datetime64) with self.assertRaises(TypeError): post2 = _ufunc_logical_skipna(a2, np.all, skipna=False)
def test_ufunc_logical_skipna_b(self) -> None: # object arrays a1 = np.array([['sdf', '', 'wer'], [True, False, True]], dtype=object) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, False, True]) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [False, False]) # string arrays a1 = np.array(['sdf', ''], dtype=str) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=0), False) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=True, axis=0), False) a1 = np.array([['sdf', '', 'wer'], ['sdf', '', 'wer']], dtype=str) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, False, True]) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [False, False]) self.assertEqual( _ufunc_logical_skipna(a1, np.any, skipna=False, axis=0).tolist(), [True, False, True]) self.assertEqual( _ufunc_logical_skipna(a1, np.any, skipna=False, axis=1).tolist(), [True, True])
def test_ufunc_logical_skipna_e(self) -> None: a1 = np.array( [['2018-01-01', '2018-02-01'], ['2018-01-01', '2018-02-01']], dtype=np.datetime64) post = _ufunc_logical_skipna(a1, np.all, skipna=True) self.assertEqual(post.tolist(), [True, True])
def test_ufunc_logical_skipna_a(self) -> None: # empty arrays a1 = np.array([], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False), True) a1 = np.array([], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.any, skipna=False), False) # float arrays 1d a1 = np.array([2.4, 5.4], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=True), True) # skippna is False, but there is non NaN, so we do not raise a1 = np.array([2.4, 0], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False), False) a1 = np.array([0, np.nan, 0], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.any, skipna=True), False) with self.assertRaises(TypeError): a1 = np.array([0, np.nan, 0], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.any, skipna=False), True) # float arrays 2d a1 = np.array([[2.4, 5.4, 3.2], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, True, True]) a1 = np.array([[2.4, 5.4, 3.2], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [True, True]) a1 = np.array([[2.4, 5.4, 0], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, True, False]) a1 = np.array([[2.4, 5.4, 0], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [False, True]) # object arrays a1 = np.array([[2.4, 5.4, 0], [2.4, None, 3.2]], dtype=object) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [False, np.nan]) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a1, np.any, skipna=False, axis=1).tolist(), [True, np.nan]) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, np.nan, False]) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a1, np.any, skipna=False, axis=0).tolist(), [True, np.nan, True]) a2 = np.array([[2.4, 5.4, 0], [2.4, np.nan, 3.2]], dtype=object) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a2, np.any, skipna=False, axis=1).tolist(), [True, np.nan]) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a2, np.all, skipna=False, axis=0).tolist(), [True, np.nan, False]) with self.assertRaises(TypeError): self.assertAlmostEqualValues( _ufunc_logical_skipna(a2, np.any, skipna=False, axis=0).tolist(), [True, np.nan, True])
def test_ufunc_logical_skipna_c(self) -> None: a1 = np.array([], dtype=float) with self.assertRaises(NotImplementedError): _ufunc_logical_skipna(a1, np.sum, skipna=True)
def test_ufunc_logical_skipna_a(self) -> None: # empty arrays a1 = np.array([], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False), True) a1 = np.array([], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.any, skipna=False), False) # float arrays 1d a1 = np.array([2.4, 5.4], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=True), True) a1 = np.array([2.4, 0], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False), False) a1 = np.array([0, np.nan, 0], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.any, skipna=True), False) a1 = np.array([0, np.nan, 0], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.any, skipna=False), True) # float arrays 2d a1 = np.array([[2.4, 5.4, 3.2], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, True, True]) a1 = np.array([[2.4, 5.4, 3.2], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [True, True]) a1 = np.array([[2.4, 5.4, 0], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, True, False]) a1 = np.array([[2.4, 5.4, 0], [2.4, 5.4, 3.2]], dtype=float) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [False, True]) # object arrays a1 = np.array([[2.4, 5.4, 0], [2.4, None, 3.2]], dtype=object) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=1).tolist(), [False, False]) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, False, False]) a1 = np.array([[2.4, 5.4, 0], [2.4, np.nan, 3.2]], dtype=object) self.assertEqual(_ufunc_logical_skipna(a1, np.all, skipna=False, axis=0).tolist(), [True, True, False])
def test_ufunc_logical_skipna_d(self) -> None: a1 = np.array(['2018-01-01', '2018-02-01'], dtype=np.datetime64) post = _ufunc_logical_skipna(a1, np.all, skipna=True) self.assertTrue(post)