Skip to content

Commit bca2240

Browse files
committed
Created fixture to check comprehensiveness
1 parent a12cb52 commit bca2240

File tree

1 file changed

+139
-31
lines changed

1 file changed

+139
-31
lines changed

pandas/tests/indexing/test_coercion.py

+139-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import itertools
34
import pytest
45
import numpy as np
56

@@ -12,6 +13,25 @@
1213
# Index / Series common tests which may trigger dtype coercions
1314
###############################################################
1415

16+
@pytest.fixture(autouse=True, scope='class')
17+
def check_comprehensiveness(request):
18+
# Iterate over combination of dtype, method and klass
19+
# and ensure that each are contained within a collected test
20+
cls = request.cls
21+
combos = itertools.product(cls.klasses, cls.dtypes, [cls.method])
22+
23+
def has_test(combo):
24+
klass, dtype, method = combo
25+
cls_funcs = request.node.session.items
26+
return any(klass in x.name and dtype in x.name and
27+
method in x.name for x in cls_funcs)
28+
29+
for combo in combos:
30+
if not has_test(combo):
31+
msg = 'test method is not defined: {0}, {1}'
32+
raise AssertionError(msg.format(type(cls), combo))
33+
34+
yield
1535

1636
class CoercionBase(object):
1737

@@ -34,15 +54,6 @@ def _assert(self, left, right, dtype):
3454
assert left.dtype == dtype
3555
assert right.dtype == dtype
3656

37-
def test_has_comprehensive_tests(self):
38-
for klass in self.klasses:
39-
for dtype in self.dtypes:
40-
method_name = 'test_{0}_{1}_{2}'.format(self.method,
41-
klass, dtype)
42-
if not hasattr(self, method_name):
43-
msg = 'test method is not defined: {0}, {1}'
44-
raise AssertionError(msg.format(type(self), method_name))
45-
4657

4758
class TestSetitemCoercion(CoercionBase):
4859

@@ -276,6 +287,27 @@ def test_setitem_index_float64(self, val, exp_dtype):
276287
exp_index = pd.Index([1.1, 2.1, 3.1, 4.1, val])
277288
self._assert_setitem_index_conversion(obj, val, exp_index, exp_dtype)
278289

290+
def test_setitem_series_period(self):
291+
pass
292+
293+
def test_setitem_index_complex128(self):
294+
pass
295+
296+
def test_setitem_index_bool(self):
297+
pass
298+
299+
def test_setitem_index_datetime64(self):
300+
pass
301+
302+
def test_setitem_index_datetime64tz(self):
303+
pass
304+
305+
def test_setitem_index_timedelta64(self):
306+
pass
307+
308+
def test_setitem_index_period(self):
309+
pass
310+
279311

280312
class TestInsertIndexCoercion(CoercionBase):
281313

@@ -329,8 +361,10 @@ def test_insert_index_float64(self, insert, coerced_val, coerced_dtype):
329361

330362
@pytest.mark.parametrize('fill_val,exp_dtype', [
331363
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
332-
(pd.Timestamp('2012-01-01', tz='US/Eastern'), 'datetime64[ns, US/Eastern]')])
333-
def test_insert_index_datetime64(self, fill_val, exp_dtype):
364+
(pd.Timestamp('2012-01-01', tz='US/Eastern'),
365+
'datetime64[ns, US/Eastern]')],
366+
ids=['datetime64', 'datetime64tz'])
367+
def test_insert_index_datetimes(self, fill_val, exp_dtype):
334368
obj = pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03',
335369
'2011-01-04'], tz=fill_val.tz)
336370
assert obj.dtype == exp_dtype
@@ -394,6 +428,12 @@ def test_insert_index_period(self, insert, coerced_val, coerced_dtype):
394428
pd.Period('2011-04', freq='M')], freq='M')
395429
self._assert_insert_conversion(obj, insert, exp, coerced_dtype)
396430

431+
def test_insert_index_complex128(self):
432+
pass
433+
434+
def test_insert_index_bool(self):
435+
pass
436+
397437

398438
class TestWhereCoercion(CoercionBase):
399439

@@ -406,7 +446,8 @@ def _assert_where_conversion(self, original, cond, values,
406446
res = target.where(cond, values)
407447
self._assert(res, expected, expected_dtype)
408448

409-
@pytest.mark.parametrize("klass", [pd.Series, pd.Index])
449+
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
450+
ids=['series', 'index'])
410451
@pytest.mark.parametrize("fill_val,exp_dtype", [
411452
(1, np.object),
412453
(1.1, np.object),
@@ -433,7 +474,8 @@ def test_where_object(self, klass, fill_val,exp_dtype):
433474
exp = klass(['a', values[1], 'c', values[3]])
434475
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
435476

436-
@pytest.mark.parametrize("klass", [pd.Series, pd.Index])
477+
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
478+
ids=['series', 'index'])
437479
@pytest.mark.parametrize("fill_val,exp_dtype", [
438480
(1, np.int64),
439481
(1.1, np.float64),
@@ -456,7 +498,8 @@ def test_where_int64(self, klass, fill_val, exp_dtype):
456498
exp = klass([1, values[1], 3, values[3]])
457499
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
458500

459-
@pytest.mark.parametrize("klass", [pd.Series, pd.Index])
501+
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
502+
ids=['series', 'index'])
460503
@pytest.mark.parametrize("fill_val, exp_dtype", [
461504
(1, np.float64),
462505
(1.1, np.float64),
@@ -523,7 +566,8 @@ def test_where_series_bool(self, fill_val, exp_dtype):
523566

524567
@pytest.mark.parametrize("fill_val,exp_dtype", [
525568
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
526-
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object)])
569+
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object)],
570+
ids=['datetime64', 'datetime64tz'])
527571
def test_where_series_datetime64(self, fill_val, exp_dtype):
528572
obj = pd.Series([pd.Timestamp('2011-01-01'),
529573
pd.Timestamp('2011-01-02'),
@@ -551,8 +595,9 @@ def test_where_series_datetime64(self, fill_val, exp_dtype):
551595

552596
@pytest.mark.parametrize("fill_val,exp_dtype", [
553597
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
554-
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object)])
555-
def test_where_index_datetime64(self, fill_val, exp_dtype):
598+
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object)],
599+
ids=['datetime64', 'datetime64tz'])
600+
def test_where_index_datetime(self, fill_val, exp_dtype):
556601
obj = pd.Index([pd.Timestamp('2011-01-01'),
557602
pd.Timestamp('2011-01-02'),
558603
pd.Timestamp('2011-01-03'),
@@ -577,6 +622,30 @@ def test_where_index_datetime64(self, fill_val, exp_dtype):
577622
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
578623
pytest.xfail("datetime64 + datetime64 -> datetime64 must support scalar")
579624

625+
def test_where_index_complex128(self):
626+
pass
627+
628+
def test_where_index_bool(self):
629+
pass
630+
631+
def test_where_series_datetime64tz(self):
632+
pass
633+
634+
def test_where_series_timedelta64(self):
635+
pass
636+
637+
def test_where_series_period(self):
638+
pass
639+
640+
def test_where_index_datetime64tz(self):
641+
pass
642+
643+
def test_where_index_timedelta64(self):
644+
pass
645+
646+
def test_where_index_period(self):
647+
pass
648+
580649

581650
class TestFillnaSeriesCoercion(CoercionBase):
582651

@@ -594,7 +663,8 @@ def _assert_fillna_conversion(self, original, value,
594663
res = target.fillna(value)
595664
self._assert(res, expected, expected_dtype)
596665

597-
@pytest.mark.parametrize("klass", [pd.Series, pd.Index])
666+
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
667+
ids=['series', 'index'])
598668
@pytest.mark.parametrize("fill_val, fill_dtype", [
599669
(1, np.object),
600670
(1.1, np.object),
@@ -607,7 +677,8 @@ def test_fillna_object(self, klass, fill_val, fill_dtype):
607677
exp = klass(['a', fill_val, 'c', 'd'])
608678
self._assert_fillna_conversion(obj, fill_val, exp, fill_dtype)
609679

610-
@pytest.mark.parametrize("klass", [pd.Series, pd.Index])
680+
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
681+
ids=['series', 'index'])
611682
@pytest.mark.parametrize("fill_val,filled_val,fill_dtype", [
612683
(1, 1.0, np.float64),
613684
(1.1, 1.1, np.float64),
@@ -637,13 +708,15 @@ def test_fillna_series_complex128(self, fill_val, fill_dtype):
637708
exp = pd.Series([1 + 1j, fill_val, 3 + 3j, 4 + 4j])
638709
self._assert_fillna_conversion(obj, fill_val, exp, fill_dtype)
639710

640-
@pytest.mark.parametrize("klass", [pd.Series, pd.Index])
711+
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
712+
ids=['series', 'index'])
641713
@pytest.mark.parametrize("fill_val,fill_dtype", [
642714
(pd.Timestamp('2012-01-01'), 'datetime64[ns]'),
643715
(pd.Timestamp('2012-01-01', tz='US/Eastern'), np.object),
644-
(1, np.object),
645-
('x', np.object)])
646-
def test_fillna_datetime64(self, klass, fill_val, fill_dtype):
716+
(1, np.object), ('x', np.object)],
717+
ids=['datetime64', 'datetime64tz',
718+
'object', 'object'])
719+
def test_fillna_datetime(self, klass, fill_val, fill_dtype):
647720
obj = klass([pd.Timestamp('2011-01-01'),
648721
pd.NaT,
649722
pd.Timestamp('2011-01-03'),
@@ -679,15 +752,37 @@ def test_fillna_datetime64tz(self, klass, fill_val, fill_dtype):
679752
pd.Timestamp('2011-01-04', tz=tz)])
680753
self._assert_fillna_conversion(obj, fill_val, exp, fill_dtype)
681754

755+
def test_fillna_series_int64(self):
756+
# int can't hold NaN
757+
pass
758+
759+
def test_fillna_index_int64(self):
760+
pass
761+
762+
def test_fillna_series_bool(self):
763+
# bool can't hold NaN
764+
pass
765+
766+
def test_fillna_index_bool(self):
767+
pass
768+
769+
def test_fillna_series_timedelta64(self):
770+
pass
682771

683-
@pytest.mark.parametrize('how', ['dict', 'series'])
684-
@pytest.mark.parametrize('to_key', [
685-
'object', 'int64', 'float64', 'complex128', 'bool', 'datetime64[ns]',
686-
'datetime64[ns, UTC]', 'datetime64[ns, US/Eastern]', 'timedelta64[ns]'])
687-
@pytest.mark.parametrize('from_key', [
688-
'object', 'int64', 'float64', 'complex128', 'bool', 'datetime64[ns]',
689-
'datetime64[ns, UTC]', 'datetime64[ns, US/Eastern]', 'timedelta64[ns]'])
690-
class TestReplaceSeriesCoercion(object):
772+
def test_fillna_series_period(self):
773+
pass
774+
775+
def test_fillna_index_timedelta64(self):
776+
pass
777+
778+
def test_fillna_index_period(self):
779+
pass
780+
781+
782+
class TestReplaceSeriesCoercion(CoercionBase):
783+
784+
klasses = ['series']
785+
method = 'replace'
691786

692787
rep = {}
693788
rep['object'] = ['a', 'b']
@@ -707,6 +802,16 @@ class TestReplaceSeriesCoercion(object):
707802
rep['timedelta64[ns]'] = [pd.Timedelta('1 day'),
708803
pd.Timedelta('2 day')]
709804

805+
@pytest.mark.parametrize('how', ['dict', 'series'])
806+
@pytest.mark.parametrize('to_key', [
807+
'object', 'int64', 'float64', 'complex128', 'bool', 'datetime64[ns]',
808+
'datetime64[ns, UTC]', 'datetime64[ns, US/Eastern]', 'timedelta64[ns]'],
809+
ids=['object', 'int64', 'float64', 'complex128',
810+
'bool', 'datetime64', 'datetime64tz', 'datetime64tz',
811+
'timedelta64'])
812+
@pytest.mark.parametrize('from_key', [
813+
'object', 'int64', 'float64', 'complex128', 'bool', 'datetime64[ns]',
814+
'datetime64[ns, UTC]', 'datetime64[ns, US/Eastern]', 'timedelta64[ns]'])
710815
def test_replace_series(self, how, to_key, from_key):
711816
if from_key == 'bool' and how == 'series' and compat.PY3:
712817
# doesn't work in PY3, though ...dict_from_bool works fine
@@ -746,3 +851,6 @@ def test_replace_series(self, how, to_key, from_key):
746851
assert exp.dtype == to_key
747852

748853
tm.assert_series_equal(result, exp)
854+
855+
def test_replace_series_period(self):
856+
pass

0 commit comments

Comments
 (0)