Skip to content

Commit 040470a

Browse files
jbrockmendeljreback
authored andcommitted
Move tests that dont belong in test_offsets (#18747)
1 parent 9705a48 commit 040470a

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

pandas/tests/scalar/test_parsing.py

+40
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,51 @@
77
import pytest
88
from dateutil.parser import parse
99

10+
import pandas as pd
1011
import pandas.util._test_decorators as td
1112
from pandas.conftest import is_dateutil_le_261, is_dateutil_gt_261
1213
from pandas import compat
1314
from pandas.util import testing as tm
1415
from pandas._libs.tslibs import parsing
16+
from pandas._libs.tslibs.parsing import parse_time_string
17+
18+
19+
def test_to_datetime1():
20+
actual = pd.to_datetime(datetime(2008, 1, 15))
21+
assert actual == datetime(2008, 1, 15)
22+
23+
actual = pd.to_datetime('20080115')
24+
assert actual == datetime(2008, 1, 15)
25+
26+
# unparseable
27+
s = 'Month 1, 1999'
28+
assert pd.to_datetime(s, errors='ignore') == s
29+
30+
31+
class TestParseQuarters(object):
32+
33+
def test_parse_time_string(self):
34+
(date, parsed, reso) = parse_time_string('4Q1984')
35+
(date_lower, parsed_lower, reso_lower) = parse_time_string('4q1984')
36+
assert date == date_lower
37+
assert parsed == parsed_lower
38+
assert reso == reso_lower
39+
40+
def test_parse_time_quarter_w_dash(self):
41+
# https://github.com/pandas-dev/pandas/issue/9688
42+
pairs = [('1988-Q2', '1988Q2'), ('2Q-1988', '2Q1988')]
43+
44+
for dashed, normal in pairs:
45+
(date_dash, parsed_dash, reso_dash) = parse_time_string(dashed)
46+
(date, parsed, reso) = parse_time_string(normal)
47+
48+
assert date_dash == date
49+
assert parsed_dash == parsed
50+
assert reso_dash == reso
51+
52+
pytest.raises(parsing.DateParseError, parse_time_string, "-2Q1992")
53+
pytest.raises(parsing.DateParseError, parse_time_string, "2-Q1992")
54+
pytest.raises(parsing.DateParseError, parse_time_string, "4-4Q1992")
1555

1656

1757
class TestDatetimeParsingWrappers(object):

pandas/tests/tseries/offsets/test_offsets.py

+1-41
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
QuarterEnd, BusinessMonthEnd, FY5253,
3030
Nano, Easter, FY5253Quarter,
3131
LastWeekOfMonth)
32-
from pandas.core.tools.datetimes import (
33-
format, ole2datetime, parse_time_string,
34-
to_datetime, DateParseError)
32+
from pandas.core.tools.datetimes import format, ole2datetime
3533
import pandas.tseries.offsets as offsets
3634
from pandas.io.pickle import read_pickle
3735
from pandas._libs.tslibs import timezones
@@ -67,18 +65,6 @@ def test_ole2datetime():
6765
ole2datetime(60)
6866

6967

70-
def test_to_datetime1():
71-
actual = to_datetime(datetime(2008, 1, 15))
72-
assert actual == datetime(2008, 1, 15)
73-
74-
actual = to_datetime('20080115')
75-
assert actual == datetime(2008, 1, 15)
76-
77-
# unparseable
78-
s = 'Month 1, 1999'
79-
assert to_datetime(s, errors='ignore') == s
80-
81-
8268
def test_normalize_date():
8369
actual = normalize_date(datetime(2007, 10, 1, 1, 12, 5, 10))
8470
assert actual == datetime(2007, 10, 1)
@@ -2800,32 +2786,6 @@ def test_get_offset_legacy():
28002786
get_offset(name)
28012787

28022788

2803-
class TestParseTimeString(object):
2804-
2805-
def test_parse_time_string(self):
2806-
(date, parsed, reso) = parse_time_string('4Q1984')
2807-
(date_lower, parsed_lower, reso_lower) = parse_time_string('4q1984')
2808-
assert date == date_lower
2809-
assert parsed == parsed_lower
2810-
assert reso == reso_lower
2811-
2812-
def test_parse_time_quarter_w_dash(self):
2813-
# https://github.com/pandas-dev/pandas/issue/9688
2814-
pairs = [('1988-Q2', '1988Q2'), ('2Q-1988', '2Q1988'), ]
2815-
2816-
for dashed, normal in pairs:
2817-
(date_dash, parsed_dash, reso_dash) = parse_time_string(dashed)
2818-
(date, parsed, reso) = parse_time_string(normal)
2819-
2820-
assert date_dash == date
2821-
assert parsed_dash == parsed
2822-
assert reso_dash == reso
2823-
2824-
pytest.raises(DateParseError, parse_time_string, "-2Q1992")
2825-
pytest.raises(DateParseError, parse_time_string, "2-Q1992")
2826-
pytest.raises(DateParseError, parse_time_string, "4-4Q1992")
2827-
2828-
28292789
def test_get_standard_freq():
28302790
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
28312791
fstr = get_standard_freq('W')

0 commit comments

Comments
 (0)