Skip to content

Commit 10fc757

Browse files
committed
Finished up parametrization of TestWhereCoercion
1 parent 101159d commit 10fc757

File tree

1 file changed

+30
-80
lines changed

1 file changed

+30
-80
lines changed

pandas/tests/indexing/test_coercion.py

+30-80
Original file line numberDiff line numberDiff line change
@@ -659,111 +659,61 @@ def test_where_series_bool(self, fill_val, exp_dtype):
659659
exp = pd.Series([True, values[1], True, values[3]])
660660
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
661661

662-
def test_where_series_datetime64(self):
662+
@pytest.mark.parametrize("fill_val,exp_dtype", [
663+
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
664+
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object)])
665+
def test_where_series_datetime64(self, fill_val, exp_dtype):
663666
obj = pd.Series([pd.Timestamp('2011-01-01'),
664667
pd.Timestamp('2011-01-02'),
665668
pd.Timestamp('2011-01-03'),
666669
pd.Timestamp('2011-01-04')])
667670
assert obj.dtype == 'datetime64[ns]'
668671
cond = pd.Series([True, False, True, False])
669672

670-
# datetime64 + datetime64 -> datetime64
671-
exp = pd.Series([pd.Timestamp('2011-01-01'),
672-
pd.Timestamp('2012-01-01'),
673-
pd.Timestamp('2011-01-03'),
674-
pd.Timestamp('2012-01-01')])
675-
self._assert_where_conversion(obj, cond, pd.Timestamp('2012-01-01'),
676-
exp, 'datetime64[ns]')
677-
678-
values = pd.Series([pd.Timestamp('2012-01-01'),
679-
pd.Timestamp('2012-01-02'),
680-
pd.Timestamp('2012-01-03'),
681-
pd.Timestamp('2012-01-04')])
682-
exp = pd.Series([pd.Timestamp('2011-01-01'),
683-
pd.Timestamp('2012-01-02'),
684-
pd.Timestamp('2011-01-03'),
685-
pd.Timestamp('2012-01-04')])
686-
self._assert_where_conversion(obj, cond, values, exp, 'datetime64[ns]')
673+
exp = pd.Series([pd.Timestamp('2011-01-01'), fill_val,
674+
pd.Timestamp('2011-01-03'), fill_val])
675+
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
687676

688-
# datetime64 + datetime64tz -> object
689-
exp = pd.Series([pd.Timestamp('2011-01-01'),
690-
pd.Timestamp('2012-01-01', tz='US/Eastern'),
691-
pd.Timestamp('2011-01-03'),
692-
pd.Timestamp('2012-01-01', tz='US/Eastern')])
693-
self._assert_where_conversion(
694-
obj, cond,
695-
pd.Timestamp('2012-01-01', tz='US/Eastern'),
696-
exp, np.object)
697-
698-
# ToDo: do not coerce to UTC, must be object
699-
values = pd.Series([pd.Timestamp('2012-01-01', tz='US/Eastern'),
700-
pd.Timestamp('2012-01-02', tz='US/Eastern'),
701-
pd.Timestamp('2012-01-03', tz='US/Eastern'),
702-
pd.Timestamp('2012-01-04', tz='US/Eastern')])
703-
exp = pd.Series([pd.Timestamp('2011-01-01'),
704-
pd.Timestamp('2012-01-02 05:00'),
705-
pd.Timestamp('2011-01-03'),
706-
pd.Timestamp('2012-01-04 05:00')])
707-
self._assert_where_conversion(obj, cond, values, exp, 'datetime64[ns]')
677+
values = pd.Series(pd.date_range(fill_val, periods=4))
678+
if fill_val.tz:
679+
exp = pd.Series([pd.Timestamp('2011-01-01'),
680+
pd.Timestamp('2012-01-02 05:00'),
681+
pd.Timestamp('2011-01-03'),
682+
pd.Timestamp('2012-01-04 05:00')])
683+
self._assert_where_conversion(obj, cond, values, exp, 'datetime64[ns]')
684+
pytest.xfail("ToDo: do not coerce to UTC, must be object")
685+
686+
exp = pd.Series([pd.Timestamp('2011-01-01'), values[1],
687+
pd.Timestamp('2011-01-03'), values[3]])
688+
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
708689

709-
def test_where_index_datetime64(self):
690+
@pytest.mark.parametrize("fill_val,exp_dtype", [
691+
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
692+
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object)])
693+
def test_where_index_datetime64(self, fill_val, exp_dtype):
710694
obj = pd.Index([pd.Timestamp('2011-01-01'),
711695
pd.Timestamp('2011-01-02'),
712696
pd.Timestamp('2011-01-03'),
713697
pd.Timestamp('2011-01-04')])
714698
assert obj.dtype == 'datetime64[ns]'
715699
cond = pd.Index([True, False, True, False])
716700

717-
# datetime64 + datetime64 -> datetime64
718-
# must support scalar
719-
msg = "cannot coerce a Timestamp with a tz on a naive Block"
720-
with pytest.raises(TypeError):
721-
obj.where(cond, pd.Timestamp('2012-01-01'))
722-
723-
values = pd.Index([pd.Timestamp('2012-01-01'),
724-
pd.Timestamp('2012-01-02'),
725-
pd.Timestamp('2012-01-03'),
726-
pd.Timestamp('2012-01-04')])
727-
exp = pd.Index([pd.Timestamp('2011-01-01'),
728-
pd.Timestamp('2012-01-02'),
729-
pd.Timestamp('2011-01-03'),
730-
pd.Timestamp('2012-01-04')])
731-
self._assert_where_conversion(obj, cond, values, exp, 'datetime64[ns]')
732-
733-
# ToDo: coerce to object
734701
msg = ("Index\\(\\.\\.\\.\\) must be called with a collection "
735702
"of some kind")
736703
with tm.assert_raises_regex(TypeError, msg):
737-
obj.where(cond, pd.Timestamp('2012-01-01', tz='US/Eastern'))
704+
obj.where(cond, fill_val)
738705

739-
# ToDo: do not ignore timezone, must be object
740-
values = pd.Index([pd.Timestamp('2012-01-01', tz='US/Eastern'),
741-
pd.Timestamp('2012-01-02', tz='US/Eastern'),
742-
pd.Timestamp('2012-01-03', tz='US/Eastern'),
743-
pd.Timestamp('2012-01-04', tz='US/Eastern')])
706+
values = pd.Index(pd.date_range(fill_val, periods=4))
744707
exp = pd.Index([pd.Timestamp('2011-01-01'),
745708
pd.Timestamp('2012-01-02'),
746709
pd.Timestamp('2011-01-03'),
747710
pd.Timestamp('2012-01-04')])
748-
self._assert_where_conversion(obj, cond, values, exp, 'datetime64[ns]')
749-
750-
def test_where_series_datetime64tz(self):
751-
pass
752-
753-
def test_where_series_timedelta64(self):
754-
pass
755711

756-
def test_where_series_period(self):
757-
pass
758-
759-
def test_where_index_datetime64tz(self):
760-
pass
761-
762-
def test_where_index_timedelta64(self):
763-
pass
764-
765-
def test_where_index_period(self):
766-
pass
712+
if fill_val.tz:
713+
self._assert_where_conversion(obj, cond, values, exp, 'datetime64[ns]')
714+
pytest.xfail("ToDo: do not ignore timezone, must be object")
715+
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
716+
pytest.xfail("datetime64 + datetime64 -> datetime64 must support scalar")
767717

768718

769719
class TestFillnaSeriesCoercion(CoercionBase):

0 commit comments

Comments
 (0)