Skip to content

Commit c201f9b

Browse files
committed
parametrize tests
1 parent af5e8ec commit c201f9b

File tree

5 files changed

+426
-444
lines changed

5 files changed

+426
-444
lines changed

pandas/tests/indexes/datetimes/test_construction.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -451,36 +451,35 @@ def test_dti_constructor_preserve_dti_freq(self):
451451
rng2 = DatetimeIndex(rng)
452452
assert rng.freq == rng2.freq
453453

454-
def test_dti_constructor_years_only(self):
454+
@pytest.mark.parametrize('tz', [None, 'UTC', 'Asia/Tokyo',
455+
'dateutil/US/Pacific'])
456+
def test_dti_constructor_years_only(self, tz):
455457
# GH 6961
456-
for tz in [None, 'UTC', 'Asia/Tokyo', 'dateutil/US/Pacific']:
457-
rng1 = date_range('2014', '2015', freq='M', tz=tz)
458-
expected1 = date_range('2014-01-31', '2014-12-31', freq='M', tz=tz)
458+
rng1 = date_range('2014', '2015', freq='M', tz=tz)
459+
expected1 = date_range('2014-01-31', '2014-12-31', freq='M', tz=tz)
459460

460-
rng2 = date_range('2014', '2015', freq='MS', tz=tz)
461-
expected2 = date_range('2014-01-01', '2015-01-01', freq='MS',
462-
tz=tz)
461+
rng2 = date_range('2014', '2015', freq='MS', tz=tz)
462+
expected2 = date_range('2014-01-01', '2015-01-01', freq='MS', tz=tz)
463463

464-
rng3 = date_range('2014', '2020', freq='A', tz=tz)
465-
expected3 = date_range('2014-12-31', '2019-12-31', freq='A', tz=tz)
464+
rng3 = date_range('2014', '2020', freq='A', tz=tz)
465+
expected3 = date_range('2014-12-31', '2019-12-31', freq='A', tz=tz)
466466

467-
rng4 = date_range('2014', '2020', freq='AS', tz=tz)
468-
expected4 = date_range('2014-01-01', '2020-01-01', freq='AS',
469-
tz=tz)
467+
rng4 = date_range('2014', '2020', freq='AS', tz=tz)
468+
expected4 = date_range('2014-01-01', '2020-01-01', freq='AS', tz=tz)
470469

471-
for rng, expected in [(rng1, expected1), (rng2, expected2),
472-
(rng3, expected3), (rng4, expected4)]:
473-
tm.assert_index_equal(rng, expected)
470+
for rng, expected in [(rng1, expected1), (rng2, expected2),
471+
(rng3, expected3), (rng4, expected4)]:
472+
tm.assert_index_equal(rng, expected)
474473

475-
def test_dti_constructor_small_int(self):
474+
@pytest.mark.parametrize('dtype', [np.int64, np.int32, np.int16, np.int8])
475+
def test_dti_constructor_small_int(self, dtype):
476476
# GH 13721
477477
exp = DatetimeIndex(['1970-01-01 00:00:00.00000000',
478478
'1970-01-01 00:00:00.00000001',
479479
'1970-01-01 00:00:00.00000002'])
480480

481-
for dtype in [np.int64, np.int32, np.int16, np.int8]:
482-
arr = np.array([0, 10, 20], dtype=dtype)
483-
tm.assert_index_equal(DatetimeIndex(arr), exp)
481+
arr = np.array([0, 10, 20], dtype=dtype)
482+
tm.assert_index_equal(DatetimeIndex(arr), exp)
484483

485484
def test_ctor_str_intraday(self):
486485
rng = DatetimeIndex(['1-1-2000 00:00:01'])
@@ -499,7 +498,7 @@ def test_index_cast_datetime64_other_units(self):
499498
assert (idx.values == conversion.ensure_datetime64ns(arr)).all()
500499

501500
def test_constructor_int64_nocopy(self):
502-
# #1624
501+
# GH#1624
503502
arr = np.arange(1000, dtype=np.int64)
504503
index = DatetimeIndex(arr)
505504

@@ -512,19 +511,17 @@ def test_constructor_int64_nocopy(self):
512511
arr[50:100] = -1
513512
assert (index.asi8[50:100] != -1).all()
514513

515-
def test_from_freq_recreate_from_data(self):
516-
freqs = ['M', 'Q', 'A', 'D', 'B', 'BH', 'T', 'S', 'L', 'U', 'H', 'N',
517-
'C']
518-
519-
for f in freqs:
520-
org = DatetimeIndex(start='2001/02/01 09:00', freq=f, periods=1)
521-
idx = DatetimeIndex(org, freq=f)
522-
tm.assert_index_equal(idx, org)
523-
524-
org = DatetimeIndex(start='2001/02/01 09:00', freq=f,
525-
tz='US/Pacific', periods=1)
526-
idx = DatetimeIndex(org, freq=f, tz='US/Pacific')
527-
tm.assert_index_equal(idx, org)
514+
@pytest.mark.parametrize('freq', ['M', 'Q', 'A', 'D', 'B', 'BH',
515+
'T', 'S', 'L', 'U', 'H', 'N', 'C'])
516+
def test_from_freq_recreate_from_data(self, freq):
517+
org = DatetimeIndex(start='2001/02/01 09:00', freq=freq, periods=1)
518+
idx = DatetimeIndex(org, freq=freq)
519+
tm.assert_index_equal(idx, org)
520+
521+
org = DatetimeIndex(start='2001/02/01 09:00', freq=freq,
522+
tz='US/Pacific', periods=1)
523+
idx = DatetimeIndex(org, freq=freq, tz='US/Pacific')
524+
tm.assert_index_equal(idx, org)
528525

529526
def test_datetimeindex_constructor_misc(self):
530527
arr = ['1/1/2005', '1/2/2005', 'Jn 3, 2005', '2005-01-04']
Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1+
import pytest
2+
13
import pandas as pd
24
import pandas.util.testing as tm
35

46

57
class TestDatetimeIndex(object):
68

7-
def test_fillna_datetime64(self):
9+
@pytest.mark.parametrize('tz', ['US/Eastern', 'Asia/Tokyo'])
10+
def test_fillna_datetime64(self, tz):
811
# GH 11343
9-
for tz in ['US/Eastern', 'Asia/Tokyo']:
10-
idx = pd.DatetimeIndex(['2011-01-01 09:00', pd.NaT,
11-
'2011-01-01 11:00'])
12-
13-
exp = pd.DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
14-
'2011-01-01 11:00'])
15-
tm.assert_index_equal(
16-
idx.fillna(pd.Timestamp('2011-01-01 10:00')), exp)
17-
18-
# tz mismatch
19-
exp = pd.Index([pd.Timestamp('2011-01-01 09:00'),
20-
pd.Timestamp('2011-01-01 10:00', tz=tz),
21-
pd.Timestamp('2011-01-01 11:00')], dtype=object)
22-
tm.assert_index_equal(
23-
idx.fillna(pd.Timestamp('2011-01-01 10:00', tz=tz)), exp)
24-
25-
# object
26-
exp = pd.Index([pd.Timestamp('2011-01-01 09:00'), 'x',
27-
pd.Timestamp('2011-01-01 11:00')], dtype=object)
28-
tm.assert_index_equal(idx.fillna('x'), exp)
29-
30-
idx = pd.DatetimeIndex(['2011-01-01 09:00', pd.NaT,
31-
'2011-01-01 11:00'], tz=tz)
32-
33-
exp = pd.DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
34-
'2011-01-01 11:00'], tz=tz)
35-
tm.assert_index_equal(
36-
idx.fillna(pd.Timestamp('2011-01-01 10:00', tz=tz)), exp)
37-
38-
exp = pd.Index([pd.Timestamp('2011-01-01 09:00', tz=tz),
39-
pd.Timestamp('2011-01-01 10:00'),
40-
pd.Timestamp('2011-01-01 11:00', tz=tz)],
41-
dtype=object)
42-
tm.assert_index_equal(
43-
idx.fillna(pd.Timestamp('2011-01-01 10:00')), exp)
44-
45-
# object
46-
exp = pd.Index([pd.Timestamp('2011-01-01 09:00', tz=tz),
47-
'x',
48-
pd.Timestamp('2011-01-01 11:00', tz=tz)],
49-
dtype=object)
50-
tm.assert_index_equal(idx.fillna('x'), exp)
12+
idx = pd.DatetimeIndex(['2011-01-01 09:00', pd.NaT,
13+
'2011-01-01 11:00'])
14+
15+
exp = pd.DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
16+
'2011-01-01 11:00'])
17+
tm.assert_index_equal(
18+
idx.fillna(pd.Timestamp('2011-01-01 10:00')), exp)
19+
20+
# tz mismatch
21+
exp = pd.Index([pd.Timestamp('2011-01-01 09:00'),
22+
pd.Timestamp('2011-01-01 10:00', tz=tz),
23+
pd.Timestamp('2011-01-01 11:00')], dtype=object)
24+
tm.assert_index_equal(
25+
idx.fillna(pd.Timestamp('2011-01-01 10:00', tz=tz)), exp)
26+
27+
# object
28+
exp = pd.Index([pd.Timestamp('2011-01-01 09:00'), 'x',
29+
pd.Timestamp('2011-01-01 11:00')], dtype=object)
30+
tm.assert_index_equal(idx.fillna('x'), exp)
31+
32+
idx = pd.DatetimeIndex(['2011-01-01 09:00', pd.NaT,
33+
'2011-01-01 11:00'], tz=tz)
34+
35+
exp = pd.DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
36+
'2011-01-01 11:00'], tz=tz)
37+
tm.assert_index_equal(
38+
idx.fillna(pd.Timestamp('2011-01-01 10:00', tz=tz)), exp)
39+
40+
exp = pd.Index([pd.Timestamp('2011-01-01 09:00', tz=tz),
41+
pd.Timestamp('2011-01-01 10:00'),
42+
pd.Timestamp('2011-01-01 11:00', tz=tz)],
43+
dtype=object)
44+
tm.assert_index_equal(
45+
idx.fillna(pd.Timestamp('2011-01-01 10:00')), exp)
46+
47+
# object
48+
exp = pd.Index([pd.Timestamp('2011-01-01 09:00', tz=tz),
49+
'x',
50+
pd.Timestamp('2011-01-01 11:00', tz=tz)],
51+
dtype=object)
52+
tm.assert_index_equal(idx.fillna('x'), exp)

0 commit comments

Comments
 (0)