8000 TST: datetime: Fix the tests to respect the date unit/time unit boundary · numpy/numpy@09f6a8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 09f6a8c

Browse files
author
Mark Wiebe
committed
TST: datetime: Fix the tests to respect the date unit/time unit boundary
1 parent a72132d commit 09f6a8c

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

numpy/core/tests/test_datetime.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,12 @@ def test_different_unit_comparison(self):
614614
dt1 = np.dtype('M8[%s]' % unit1)
615615
for unit2 in ['D', 'h', 'm', 's', 'ms', 'us']:
616616
dt2 = np.dtype('M8[%s]' % unit2)
617-
assert_equal(np.array('1932-02-17', dtype='M').astype(dt1),
618-
np.array('1932-02-17T00:00:00Z', dtype='M').astype(dt2))
619-
assert_equal(np.array('10000-04-27', dtype='M').astype(dt1),
620-
np.array('10000-04-27T00:00:00Z', dtype='M').astype(dt2))
617+
assert_(np.equal(np.array('1932-02-17', dtype='M').astype(dt1),
618+
np.array('1932-02-17T00:00:00Z', dtype='M').astype(dt2),
619+
casting='unsafe'))
620+
assert_(np.equal(np.array('10000-04-27', dtype='M').astype(dt1),
621+
np.array('10000-04-27T00:00:00Z', dtype='M').astype(dt2),
622+
casting='unsafe'))
621623

622624
# Shouldn't be able to compare datetime and timedelta
623625
# TODO: Changing to 'same_kind' or 'safe' casting in the ufuncs by
@@ -732,10 +734,12 @@ def test_datetime_add(self):
732734
assert_equal((tda + dta).dtype, np.dtype('M8[D]'))
733735

734736
# In M8 + m8, the result goes to higher precision
735-
assert_equal(dta + tdb, dtc)
736-
assert_equal((dta + tdb).dtype, np.dtype('M8[h]'))
737-
assert_equal(tdb + dta, dtc)
738-
assert_equal((tdb + dta).dtype, np.dtype('M8[h]'))
737+
assert_equal(np.add(dta, tdb, casting='unsafe'), dtc)
738+
assert_equal(np.add(dta, tdb, casting='unsafe').dtype,
739+
np.dtype('M8[h]'))
740+
assert_equal(np.add(tdb, dta, casting='unsafe'), dtc)
741+
assert_equal(np.add(tdb, dta, casting='unsafe').dtype,
742+
np.dtype('M8[h]'))
739743

740744
# M8 + M8
741745
assert_raises(TypeError, np.add, dta, dtb)
@@ -794,14 +798,19 @@ def test_datetime_subtract(self):
794798
assert_equal((dtb - tda).dtype, np.dtype('M8[D]'))
795799

796800
# In M8 - m8, the result goes to higher precision
797-
assert_equal(dtc - tdb, dte)
798-
assert_equal((dtc - tdb).dtype, np.dtype('M8[h]'))
801+
assert_equal(np.subtract(dtc, tdb, casting='unsafe'), dte)
802+
assert_equal(np.subtract(dtc, tdb, casting='unsafe').dtype,
803+
np.dtype('M8[h]'))
799804

800805
# M8 - M8 with different goes to higher precision
801-
assert_equal(dtc - dtd, np.timedelta64(0,'h'))
802-
assert_equal((dtc - dtd).dtype, np.dtype('m8[h]'))
803-
assert_equal(dtd - dtc, np.timedelta64(0,'h'))
804-
assert_equal((dtd - dtc).dtype, np.dtype('m8[h]'))
806+
assert_equal(np.subtract(dtc, dtd, casting='unsafe'),
807+
np.timedelta64(0,'h'))
808+
assert_equal(np.subtract(dtc, dtd, casting='unsafe').dtype,
809+
np.dtype('m8[h]'))
810+
assert_equal(np.subtract(dtd, dtc, casting='unsafe'),
811+
np.timedelta64(0,'h'))
812+
assert_equal(np.subtract(dtd, dtc, casting='unsafe').dtype,
813+
np.dtype('m8[h]'))
805814

806815
# m8 - M8
807816
assert_raises(TypeError, np.subtract, tda, dta)
@@ -915,7 +924,7 @@ def test_datetime_minmax(self):
915924

916925
# Interaction with NaT
917926
a = np.array('1999-03-12T13Z', dtype='M8[2m]')
918-
dtnat = np.array('NaT', dtype='M8[D]')
927+
dtnat = np.array('NaT', dtype='M8[h]')
919928
assert_equal(np.minimum(a,dtnat), a)
920929
assert_equal(np.minimum(dtnat,a), a)
921930
assert_equal(np.maximum(a,dtnat), a)

0 commit comments

Comments
 (0)
0