MCPcopy Create free account
hub / github.com/numpy/numpy / test_datetime_multiply

Method test_datetime_multiply

numpy/core/tests/test_datetime.py:1208–1262  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1206 assert_raises(TypeError, np.subtract, 3, dta)
1207
1208 def test_datetime_multiply(self):
1209 for dta, tda, tdb, tdc in \
1210 [
1211 # One-dimensional arrays
1212 (np.array(['2012-12-21'], dtype='M8[D]'),
1213 np.array([6], dtype='m8[h]'),
1214 np.array([9], dtype='m8[h]'),
1215 np.array([12], dtype='m8[h]')),
1216 # NumPy scalars
1217 (np.datetime64('2012-12-21', '[D]'),
1218 np.timedelta64(6, '[h]'),
1219 np.timedelta64(9, '[h]'),
1220 np.timedelta64(12, '[h]'))]:
1221 # m8 * int
1222 assert_equal(tda * 2, tdc)
1223 assert_equal((tda * 2).dtype, np.dtype('m8[h]'))
1224 # int * m8
1225 assert_equal(2 * tda, tdc)
1226 assert_equal((2 * tda).dtype, np.dtype('m8[h]'))
1227 # m8 * float
1228 assert_equal(tda * 1.5, tdb)
1229 assert_equal((tda * 1.5).dtype, np.dtype('m8[h]'))
1230 # float * m8
1231 assert_equal(1.5 * tda, tdb)
1232 assert_equal((1.5 * tda).dtype, np.dtype('m8[h]'))
1233
1234 # m8 * m8
1235 assert_raises(TypeError, np.multiply, tda, tdb)
1236 # m8 * M8
1237 assert_raises(TypeError, np.multiply, dta, tda)
1238 # M8 * m8
1239 assert_raises(TypeError, np.multiply, tda, dta)
1240 # M8 * int
1241 assert_raises(TypeError, np.multiply, dta, 2)
1242 # int * M8
1243 assert_raises(TypeError, np.multiply, 2, dta)
1244 # M8 * float
1245 assert_raises(TypeError, np.multiply, dta, 1.5)
1246 # float * M8
1247 assert_raises(TypeError, np.multiply, 1.5, dta)
1248
1249 # NaTs
1250 with suppress_warnings() as sup:
1251 sup.filter(RuntimeWarning, "invalid value encountered in multiply")
1252 nat = np.timedelta64('NaT')
1253 def check(a, b, res):
1254 assert_equal(a * b, res)
1255 assert_equal(b * a, res)
1256 for tp in (int, float):
1257 check(nat, tp(2), nat)
1258 check(nat, tp(0), nat)
1259 for f in (float('inf'), float('nan')):
1260 check(np.timedelta64(1), f, nat)
1261 check(np.timedelta64(0), f, nat)
1262 check(nat, f, nat)
1263
1264 @pytest.mark.parametrize("op1, op2, exp", [
1265 # m8 same units round down

Callers

nothing calls this directly

Calls 6

assert_equalFunction · 0.90
assert_raisesFunction · 0.90
suppress_warningsClass · 0.90
checkFunction · 0.85
filterMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected