@@ -310,21 +310,22 @@ def test_to_datetime_tz_psycopg2(self):
310
310
def test_datetime_bool (self ):
311
311
# GH13176
312
312
with self .assertRaises (TypeError ):
313
- to_datetime (False )
314
- self .assertTrue (to_datetime (False , errors = "coerce" ) is NaT )
315
- self .assertEqual (to_datetime (False , errors = "ignore" ), False )
313
+ to_datetime (False , unit = 'ns' )
314
+ self .assertTrue (to_datetime (False , unit = 'ns' , errors = "coerce" ) is NaT )
315
+ self .assertEqual (to_datetime (False , unit = 'ns' , errors = "ignore" ), False )
316
316
with self .assertRaises (TypeError ):
317
- to_datetime (True )
318
- self .assertTrue (to_datetime (True , errors = "coerce" ) is NaT )
319
- self .assertEqual (to_datetime (True , errors = "ignore" ), True )
317
+ to_datetime (True , unit = 'ns' )
318
+ self .assertTrue (to_datetime (True , unit = 'ns' , errors = "coerce" ) is NaT )
319
+ self .assertEqual (to_datetime (True , unit = 'ns' , errors = "ignore" ), True )
320
320
with self .assertRaises (TypeError ):
321
- to_datetime ([False , datetime .today ()])
321
+ to_datetime ([False , datetime .today ()], unit = 'ns' )
322
322
with self .assertRaises (TypeError ):
323
- to_datetime (['20130101' , True ])
323
+ to_datetime (['20130101' , True ], unit = 'ns' )
324
324
tm .assert_index_equal (to_datetime ([0 , False , NaT , 0.0 ],
325
+ unit = 'ns' ,
325
326
errors = "coerce" ),
326
- DatetimeIndex ([to_datetime (0 ), NaT ,
327
- NaT , to_datetime (0 )]))
327
+ DatetimeIndex ([to_datetime (0 , unit = 'ns' ), NaT ,
328
+ NaT , to_datetime (0 , unit = 'ns' )]))
328
329
329
330
def test_datetime_invalid_datatype (self ):
330
331
# GH13176
@@ -410,10 +411,10 @@ def test_unit_with_numeric(self):
410
411
arr1 = [1.434692e+18 , 1.432766e+18 ]
411
412
arr2 = np .array (arr1 ).astype ('int64' )
412
413
for errors in ['ignore' , 'raise' , 'coerce' ]:
413
- result = pd .to_datetime (arr1 , errors = errors )
414
+ result = pd .to_datetime (arr1 , unit = 'ns' , errors = errors )
414
415
tm .assert_index_equal (result , expected )
415
416
416
- result = pd .to_datetime (arr2 , errors = errors )
417
+ result = pd .to_datetime (arr2 , unit = 'ns' , errors = errors )
417
418
tm .assert_index_equal (result , expected )
418
419
419
420
# but we want to make sure that we are coercing
@@ -422,15 +423,15 @@ def test_unit_with_numeric(self):
422
423
'2015-06-19 05:33:20' ,
423
424
'2015-05-27 22:33:20' ])
424
425
arr = ['foo' , 1.434692e+18 , 1.432766e+18 ]
425
- result = pd .to_datetime (arr , errors = 'coerce' )
426
+ result = pd .to_datetime (arr , unit = 'ns' , errors = 'coerce' )
426
427
tm .assert_index_equal (result , expected )
427
428
428
429
expected = DatetimeIndex (['2015-06-19 05:33:20' ,
429
430
'2015-05-27 22:33:20' ,
430
431
'NaT' ,
431
432
'NaT' ])
432
433
arr = [1.434692e+18 , 1.432766e+18 , 'foo' , 'NaT' ]
433
- result = pd .to_datetime (arr , errors = 'coerce' )
434
+ result = pd .to_datetime (arr , unit = 'ns' , errors = 'coerce' )
434
435
tm .assert_index_equal (result , expected )
435
436
436
437
def test_unit_mixed (self ):
@@ -442,17 +443,17 @@ def test_unit_mixed(self):
442
443
tm .assert_index_equal (result , expected )
443
444
444
445
with self .assertRaises (ValueError ):
445
- pd .to_datetime (arr , errors = 'raise' )
446
+ pd .to_datetime (arr , unit = 'ns' , errors = 'raise' )
446
447
447
448
expected = DatetimeIndex (['NaT' ,
448
449
'NaT' ,
449
450
'2013-01-01' ])
450
451
arr = [1.434692e+18 , 1.432766e+18 , pd .Timestamp ('20130101' )]
451
- result = pd .to_datetime (arr , errors = 'coerce' )
452
+ result = pd .to_datetime (arr , unit = 'ns' , errors = 'coerce' )
452
453
tm .assert_index_equal (result , expected )
453
454
454
455
with self .assertRaises (ValueError ):
455
- pd .to_datetime (arr , errors = 'raise' )
456
+ pd .to_datetime (arr , unit = 'ns' , errors = 'raise' )
456
457
457
458
def test_dataframe (self ):
458
459
@@ -688,7 +689,7 @@ def test_to_datetime_types(self):
688
689
689
690
# ints
690
691
result = Timestamp (0 )
691
- expected = to_datetime (0 )
692
+ expected = to_datetime (0 , unit = 'ns' )
692
693
self .assertEqual (result , expected )
693
694
694
695
# GH 3888 (strings)
@@ -715,6 +716,14 @@ def test_to_datetime_unprocessable_input(self):
715
716
)
716
717
self .assertRaises (TypeError , to_datetime , [1 , '1' ], errors = 'raise' )
717
718
719
+ @pytest .mark .parametrize ('arg' , [int (1 ), float (1 ), range (5 ),
720
+ np .array (range (5 ), 'd' )])
721
+ @staticmethod
722
+ def test_to_datetime_numerical_input (arg ):
723
+ # GH15836
724
+ with pytest .raises (ValueError ):
725
+ pd .to_datetime (arg )
726
+
718
727
def test_to_datetime_other_datetime64_units (self ):
719
728
# 5/25/2012
720
729
scalar = np .int64 (1337904000000000 ).view ('M8[us]' )
0 commit comments