@@ -581,6 +581,12 @@ def test_constructor_pass_none(self):
581581 s = Series (None , index = lrange (5 ), dtype = object )
582582 self .assertEqual (s .dtype , np .object_ )
583583
584+ # GH 7431
585+ # inference on the index
586+ s = Series (index = np .array ([None ]))
587+ expected = Series (index = Index ([None ]))
588+ assert_series_equal (s ,expected )
589+
584590 def test_constructor_cast (self ):
585591 self .assertRaises (ValueError , Series , ['a' , 'b' , 'c' ], dtype = float )
586592
@@ -669,6 +675,16 @@ def test_constructor_dtype_datetime64(self):
669675 self .assert_numpy_array_equal (series1 .values ,dates2 )
670676 self .assertEqual (series1 .dtype ,object )
671677
678+ # these will correctly infer a datetime
679+ s = Series ([None , pd .NaT , '2013-08-05 15:30:00.000001' ])
680+ self .assertEqual (s .dtype ,'datetime64[ns]' )
681+ s = Series ([np .nan , pd .NaT , '2013-08-05 15:30:00.000001' ])
682+ self .assertEqual (s .dtype ,'datetime64[ns]' )
683+ s = Series ([pd .NaT , None , '2013-08-05 15:30:00.000001' ])
684+ self .assertEqual (s .dtype ,'datetime64[ns]' )
685+ s = Series ([pd .NaT , np .nan , '2013-08-05 15:30:00.000001' ])
686+ self .assertEqual (s .dtype ,'datetime64[ns]' )
687+
672688 def test_constructor_dict (self ):
673689 d = {'a' : 0. , 'b' : 1. , 'c' : 2. }
674690 result = Series (d , index = ['b' , 'c' , 'd' , 'a' ])
@@ -2462,6 +2478,18 @@ def f():
24622478 td = Series ([timedelta (days = i ) for i in range (3 )] + ['foo' ])
24632479 self .assertEqual (td .dtype , 'object' )
24642480
2481+ # these will correctly infer a timedelta
2482+ # but only on numpy > 1.7 as the cython path will only be used
2483+ if not _np_version_under1p7 :
2484+ s = Series ([None , pd .NaT , '1 Day' ])
2485+ self .assertEqual (s .dtype ,'timedelta64[ns]' )
2486+ s = Series ([np .nan , pd .NaT , '1 Day' ])
2487+ self .assertEqual (s .dtype ,'timedelta64[ns]' )
2488+ s = Series ([pd .NaT , None , '1 Day' ])
2489+ self .assertEqual (s .dtype ,'timedelta64[ns]' )
2490+ s = Series ([pd .NaT , np .nan , '1 Day' ])
2491+ self .assertEqual (s .dtype ,'timedelta64[ns]' )
2492+
24652493 def test_operators_timedelta64 (self ):
24662494
24672495 # invalid ops
@@ -2939,12 +2967,12 @@ def test_datetime64_fillna(self):
29392967
29402968 # GH 6587
29412969 # make sure that we are treating as integer when filling
2970+ # this also tests inference of a datetime-like with NaT's
29422971 s = Series ([pd .NaT , pd .NaT , '2013-08-05 15:30:00.000001' ])
29432972 expected = Series (['2013-08-05 15:30:00.000001' , '2013-08-05 15:30:00.000001' , '2013-08-05 15:30:00.000001' ], dtype = 'M8[ns]' )
29442973 result = s .fillna (method = 'backfill' )
29452974 assert_series_equal (result , expected )
29462975
2947-
29482976 def test_fillna_int (self ):
29492977 s = Series (np .random .randint (- 100 , 100 , 50 ))
29502978 s .fillna (method = 'ffill' , inplace = True )
0 commit comments