def test_randomDate(self): """randomDate should give known result""" try: from matplotlib.dates import date2num, num2date except ImportError: return # don't even do the test dt1 = datetime.datetime(2000, 1, 1) dt2 = datetime.datetime(2000, 2, 1) numpy.random.seed(8675309) ans = numpy.array( [ datetime.datetime(2000, 1, 26, 4, 28, 10, 500070), datetime.datetime(2000, 1, 24, 6, 46, 39, 156905), datetime.datetime(2000, 1, 12, 1, 52, 50, 481431), datetime.datetime(2000, 1, 7, 6, 30, 26, 331312), datetime.datetime(2000, 1, 13, 16, 17, 48, 619577), ] ) numpy.testing.assert_array_equal(ans, t.randomDate(dt1, dt2, 5, sorted=False)) # check the exception dt11 = num2date(date2num(dt1)) self.assertRaises(ValueError, t.randomDate, dt11, dt2) ans.sort() numpy.random.seed(8675309) numpy.testing.assert_array_equal(ans, t.randomDate(dt1, dt2, 5, sorted=True)) numpy.random.seed(8675309) numpy.testing.assert_array_equal(ans, t.randomDate(dt1, dt2, 5, sorted=True, tzinfo="MDT"))
def test_randomDate(self): """randomDate should give known result""" try: from matplotlib.dates import date2num, num2date except ImportError: return # don't even do the test dt1 = datetime.datetime(2000, 1, 1) dt2 = datetime.datetime(2000, 2, 1) numpy.random.seed(8675309) ans = numpy.array([ datetime.datetime(2000, 1, 26, 4, 28, 10, 500070), datetime.datetime(2000, 1, 24, 6, 46, 39, 156905), datetime.datetime(2000, 1, 12, 1, 52, 50, 481431), datetime.datetime(2000, 1, 7, 6, 30, 26, 331312), datetime.datetime(2000, 1, 13, 16, 17, 48, 619577) ]) numpy.testing.assert_array_equal( ans, t.randomDate(dt1, dt2, 5, sorted=False)) # check the exception dt11 = num2date(date2num(dt1)) self.assertRaises(ValueError, t.randomDate, dt11, dt2) ans.sort() numpy.random.seed(8675309) numpy.testing.assert_array_equal( ans, t.randomDate(dt1, dt2, 5, sorted=True)) numpy.random.seed(8675309) numpy.testing.assert_array_equal( ans, t.randomDate(dt1, dt2, 5, sorted=True, tzinfo='MDT'))
def test_randomDate(self): """randomDate should give known result""" try: from matplotlib.dates import date2num, num2date except ImportError: return # don't even do the test dt1 = datetime.datetime(2000, 1, 1) dt2 = datetime.datetime(2000, 2, 1) numpy.random.seed(8675309) ans = numpy.array([ datetime.datetime(2000, 1, 26, 4, 28, 10, 500070), datetime.datetime(2000, 1, 24, 6, 46, 39, 156905), datetime.datetime(2000, 1, 12, 1, 52, 50, 481431), datetime.datetime(2000, 1, 7, 6, 30, 26, 331312), datetime.datetime(2000, 1, 13, 16, 17, 48, 619577) ]) ntests = len(ans) res = t.randomDate(dt1, dt2, ntests, sorted=False) #results are different at microsecond level between Python2 and Python3 #one likely cause is the difference in behavior of round() between versions #so, we'll round off all the microseconds fields here for ii in range(ntests): ans[ii] = ans[ii].replace(microsecond=100 * (ans[ii].microsecond // 100)) res[ii] = res[ii].replace(microsecond=100 * (res[ii].microsecond // 100)) #TODO: improve testing for randomDate numpy.testing.assert_array_equal(ans, res) # check the exception dt11 = num2date(date2num(dt1)) self.assertRaises(ValueError, t.randomDate, dt11, dt2) ans.sort() numpy.random.seed(8675309) res = t.randomDate(dt1, dt2, ntests, sorted=True) for ii in range(ntests): res[ii] = res[ii].replace(microsecond=100 * (res[ii].microsecond // 100)) numpy.testing.assert_array_equal(ans, res) numpy.random.seed(8675309) res = t.randomDate(dt1, dt2, ntests, sorted=True, tzinfo='MDT') for ii in range(ntests): res[ii] = res[ii].replace(microsecond=100 * (res[ii].microsecond // 100)) numpy.testing.assert_array_equal(ans, res)
def test_randomDate(self): """randomDate should give known result""" try: from matplotlib.dates import date2num, num2date except ImportError: return # don't even do the test dt1 = datetime.datetime(2000, 1, 1) dt2 = datetime.datetime(2000, 2, 1) numpy.random.seed(8675309) ans = numpy.array([datetime.datetime(2000, 1, 26, 4, 28, 10, 500070), datetime.datetime(2000, 1, 24, 6, 46, 39, 156905), datetime.datetime(2000, 1, 12, 1, 52, 50, 481431), datetime.datetime(2000, 1, 7, 6, 30, 26, 331312), datetime.datetime(2000, 1, 13, 16, 17, 48, 619577)]) ntests = len(ans) res = t.randomDate(dt1, dt2, ntests, sorted=False) #results are different at microsecond level between Python2 and Python3 #one likely cause is the difference in behavior of round() between versions #so, we'll round off all the microseconds fields here for ii in range(ntests): ans[ii] = ans[ii].replace(microsecond=100*(ans[ii].microsecond//100)) res[ii] = res[ii].replace(microsecond=100*(res[ii].microsecond//100)) #TODO: improve testing for randomDate numpy.testing.assert_array_equal(ans, res) # check the exception dt11 = num2date(date2num(dt1)) self.assertRaises(ValueError, t.randomDate, dt11, dt2) ans.sort() numpy.random.seed(8675309) res = t.randomDate(dt1, dt2, ntests, sorted=True) for ii in range(ntests): res[ii] = res[ii].replace(microsecond=100*(res[ii].microsecond//100)) numpy.testing.assert_array_equal(ans, res) numpy.random.seed(8675309) res = t.randomDate(dt1, dt2, ntests, sorted=True, tzinfo='MDT') for ii in range(ntests): res[ii] = res[ii].replace(microsecond=100*(res[ii].microsecond//100)) numpy.testing.assert_array_equal(ans, res)