Skip to content

Commit a3a8327

Browse files
committed
Parametrized datetime tests for TestInsertIndexCoercion
1 parent 10fc757 commit a3a8327

File tree

1 file changed

+15
-43
lines changed

1 file changed

+15
-43
lines changed

pandas/tests/indexing/test_coercion.py

+15-43
Original file line numberDiff line numberDiff line change
@@ -437,60 +437,32 @@ def test_insert_index_float64(self, insert, coerced_val, coerced_dtype):
437437
exp = pd.Index([1., coerced_val, 2., 3., 4.])
438438
self._assert_insert_conversion(obj, insert, exp, coerced_dtype)
439439

440-
def test_insert_index_complex128(self):
441-
pass
442-
443-
def test_insert_index_bool(self):
444-
pass
445-
446-
def test_insert_index_datetime64(self):
447-
obj = pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03',
448-
'2011-01-04'])
449-
assert obj.dtype == 'datetime64[ns]'
450-
451-
# datetime64 + datetime64 => datetime64
452-
exp = pd.DatetimeIndex(['2011-01-01', '2012-01-01', '2011-01-02',
453-
'2011-01-03', '2011-01-04'])
454-
self._assert_insert_conversion(obj, pd.Timestamp('2012-01-01'),
455-
exp, 'datetime64[ns]')
456-
457-
# ToDo: must coerce to object
458-
msg = "Passed item and index have different timezone"
459-
with tm.assert_raises_regex(ValueError, msg):
460-
obj.insert(1, pd.Timestamp('2012-01-01', tz='US/Eastern'))
461-
462-
# ToDo: must coerce to object
463-
msg = "cannot insert DatetimeIndex with incompatible label"
464-
with tm.assert_raises_regex(TypeError, msg):
465-
obj.insert(1, 1)
466-
467-
def test_insert_index_datetime64tz(self):
440+
@pytest.mark.parametrize('fill_val,exp_dtype', [
441+
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
442+
(pd.Timestamp('2012-01-01', tz='US/Eastern'), 'datetime64[ns, US/Eastern]')])
443+
def test_insert_index_datetime64(self, fill_val, exp_dtype):
468444
obj = pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03',
469-
'2011-01-04'], tz='US/Eastern')
470-
assert obj.dtype == 'datetime64[ns, US/Eastern]'
471-
472-
# datetime64tz + datetime64tz => datetime64
473-
exp = pd.DatetimeIndex(['2011-01-01', '2012-01-01', '2011-01-02',
474-
'2011-01-03', '2011-01-04'], tz='US/Eastern')
475-
val = pd.Timestamp('2012-01-01', tz='US/Eastern')
476-
self._assert_insert_conversion(obj, val, exp,
477-
'datetime64[ns, US/Eastern]')
445+
'2011-01-04'], tz=fill_val.tz)
446+
assert obj.dtype == exp_dtype
478447

479-
# ToDo: must coerce to object
480-
msg = "Passed item and index have different timezone"
481-
with tm.assert_raises_regex(ValueError, msg):
482-
obj.insert(1, pd.Timestamp('2012-01-01'))
448+
exp = pd.DatetimeIndex(['2011-01-01', fill_val.date(), '2011-01-02',
449+
'2011-01-03', '2011-01-04'], tz=fill_val.tz)
450+
self._assert_insert_conversion(obj, fill_val, exp, exp_dtype)
483451

484-
# ToDo: must coerce to object
485452
msg = "Passed item and index have different timezone"
453+
if fill_val.tz:
454+
with tm.assert_raises_regex(ValueError, msg):
455+
obj.insert(1, pd.Timestamp('2012-01-01'))
456+
486457
with tm.assert_raises_regex(ValueError, msg):
487458
obj.insert(1, pd.Timestamp('2012-01-01', tz='Asia/Tokyo'))
488459

489-
# ToDo: must coerce to object
490460
msg = "cannot insert DatetimeIndex with incompatible label"
491461
with tm.assert_raises_regex(TypeError, msg):
492462
obj.insert(1, 1)
493463

464+
pytest.xfail("ToDo: must coerce to object")
465+
494466
def test_insert_index_timedelta64(self):
495467
obj = pd.TimedeltaIndex(['1 day', '2 day', '3 day', '4 day'])
496468
assert obj.dtype == 'timedelta64[ns]'

0 commit comments

Comments
 (0)