Skip to content

Commit c6f057c

Browse files
jbrockmendelNo-Stream
authored andcommitted
Separate tests specific to tslibs modules (pandas-dev#18036)
1 parent 82a40fe commit c6f057c

File tree

3 files changed

+149
-176
lines changed

3 files changed

+149
-176
lines changed

pandas/tests/indexes/datetimes/test_ops.py

+3-49
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import dateutil
44
import warnings
55
import numpy as np
6-
from datetime import timedelta
6+
from datetime import timedelta, datetime
77

88
from itertools import product
99
import pandas as pd
@@ -12,7 +12,7 @@
1212
from pandas.errors import PerformanceWarning
1313
from pandas import (DatetimeIndex, PeriodIndex, Series, Timestamp, Timedelta,
1414
date_range, TimedeltaIndex, _np_version_under1p10, Index,
15-
datetime, Float64Index, offsets, bdate_range)
15+
bdate_range)
1616
from pandas.tseries.offsets import BMonthEnd, CDay, BDay
1717
from pandas.tests.test_base import Ops
1818

@@ -952,52 +952,6 @@ def test_equals(self):
952952
assert not idx.equals(pd.Series(idx3))
953953

954954

955-
class TestDateTimeIndexToJulianDate(object):
956-
957-
def test_1700(self):
958-
r1 = Float64Index([2345897.5, 2345898.5, 2345899.5, 2345900.5,
959-
2345901.5])
960-
r2 = date_range(start=Timestamp('1710-10-01'), periods=5,
961-
freq='D').to_julian_date()
962-
assert isinstance(r2, Float64Index)
963-
tm.assert_index_equal(r1, r2)
964-
965-
def test_2000(self):
966-
r1 = Float64Index([2451601.5, 2451602.5, 2451603.5, 2451604.5,
967-
2451605.5])
968-
r2 = date_range(start=Timestamp('2000-02-27'), periods=5,
969-
freq='D').to_julian_date()
970-
assert isinstance(r2, Float64Index)
971-
tm.assert_index_equal(r1, r2)
972-
973-
def test_hour(self):
974-
r1 = Float64Index(
975-
[2451601.5, 2451601.5416666666666666, 2451601.5833333333333333,
976-
2451601.625, 2451601.6666666666666666])
977-
r2 = date_range(start=Timestamp('2000-02-27'), periods=5,
978-
freq='H').to_julian_date()
979-
assert isinstance(r2, Float64Index)
980-
tm.assert_index_equal(r1, r2)
981-
982-
def test_minute(self):
983-
r1 = Float64Index(
984-
[2451601.5, 2451601.5006944444444444, 2451601.5013888888888888,
985-
2451601.5020833333333333, 2451601.5027777777777777])
986-
r2 = date_range(start=Timestamp('2000-02-27'), periods=5,
987-
freq='T').to_julian_date()
988-
assert isinstance(r2, Float64Index)
989-
tm.assert_index_equal(r1, r2)
990-
991-
def test_second(self):
992-
r1 = Float64Index(
993-
[2451601.5, 2451601.500011574074074, 2451601.5000231481481481,
994-
2451601.5000347222222222, 2451601.5000462962962962])
995-
r2 = date_range(start=Timestamp('2000-02-27'), periods=5,
996-
freq='S').to_julian_date()
997-
assert isinstance(r2, Float64Index)
998-
tm.assert_index_equal(r1, r2)
999-
1000-
1001955
# GH 10699
1002956
@pytest.mark.parametrize('klass,assert_func', zip([Series, DatetimeIndex],
1003957
[tm.assert_series_equal,
@@ -1123,7 +1077,7 @@ def test_shift_months(years, months):
11231077
Timestamp('2000-12-31')])
11241078
actual = DatetimeIndex(tslib.shift_months(s.asi8, years * 12 +
11251079
months))
1126-
expected = DatetimeIndex([x + offsets.DateOffset(
1080+
expected = DatetimeIndex([x + pd.offsets.DateOffset(
11271081
years=years, months=months) for x in s])
11281082
tm.assert_index_equal(actual, expected)
11291083

pandas/tests/indexes/datetimes/test_tools.py

+7-127
Original file line numberDiff line numberDiff line change
@@ -897,69 +897,6 @@ def test_dayfirst(self):
897897

898898

899899
class TestGuessDatetimeFormat(object):
900-
901-
def test_guess_datetime_format_with_parseable_formats(self):
902-
tm._skip_if_not_us_locale()
903-
dt_string_to_format = (('20111230', '%Y%m%d'),
904-
('2011-12-30', '%Y-%m-%d'),
905-
('30-12-2011', '%d-%m-%Y'),
906-
('2011-12-30 00:00:00', '%Y-%m-%d %H:%M:%S'),
907-
('2011-12-30T00:00:00', '%Y-%m-%dT%H:%M:%S'),
908-
('2011-12-30 00:00:00.000000',
909-
'%Y-%m-%d %H:%M:%S.%f'), )
910-
911-
for dt_string, dt_format in dt_string_to_format:
912-
assert tools._guess_datetime_format(dt_string) == dt_format
913-
914-
def test_guess_datetime_format_with_dayfirst(self):
915-
ambiguous_string = '01/01/2011'
916-
assert tools._guess_datetime_format(
917-
ambiguous_string, dayfirst=True) == '%d/%m/%Y'
918-
assert tools._guess_datetime_format(
919-
ambiguous_string, dayfirst=False) == '%m/%d/%Y'
920-
921-
def test_guess_datetime_format_with_locale_specific_formats(self):
922-
# The month names will vary depending on the locale, in which
923-
# case these wont be parsed properly (dateutil can't parse them)
924-
tm._skip_if_has_locale()
925-
926-
dt_string_to_format = (('30/Dec/2011', '%d/%b/%Y'),
927-
('30/December/2011', '%d/%B/%Y'),
928-
('30/Dec/2011 00:00:00', '%d/%b/%Y %H:%M:%S'), )
929-
930-
for dt_string, dt_format in dt_string_to_format:
931-
assert tools._guess_datetime_format(dt_string) == dt_format
932-
933-
def test_guess_datetime_format_invalid_inputs(self):
934-
# A datetime string must include a year, month and a day for it
935-
# to be guessable, in addition to being a string that looks like
936-
# a datetime
937-
invalid_dts = [
938-
'2013',
939-
'01/2013',
940-
'12:00:00',
941-
'1/1/1/1',
942-
'this_is_not_a_datetime',
943-
'51a',
944-
9,
945-
datetime(2011, 1, 1),
946-
]
947-
948-
for invalid_dt in invalid_dts:
949-
assert tools._guess_datetime_format(invalid_dt) is None
950-
951-
def test_guess_datetime_format_nopadding(self):
952-
# GH 11142
953-
dt_string_to_format = (('2011-1-1', '%Y-%m-%d'),
954-
('30-1-2011', '%d-%m-%Y'),
955-
('1/1/2011', '%m/%d/%Y'),
956-
('2011-1-1 00:00:00', '%Y-%m-%d %H:%M:%S'),
957-
('2011-1-1 0:0:0', '%Y-%m-%d %H:%M:%S'),
958-
('2011-1-3T00:00:0', '%Y-%m-%dT%H:%M:%S'))
959-
960-
for dt_string, dt_format in dt_string_to_format:
961-
assert tools._guess_datetime_format(dt_string) == dt_format
962-
963900
def test_guess_datetime_format_for_array(self):
964901
tm._skip_if_not_us_locale()
965902
expected_format = '%Y-%m-%d %H:%M:%S.%f'
@@ -1074,21 +1011,6 @@ def test_day_not_in_month_ignore(self):
10741011

10751012

10761013
class TestDatetimeParsingWrappers(object):
1077-
def test_does_not_convert_mixed_integer(self):
1078-
bad_date_strings = ('-50000', '999', '123.1234', 'm', 'T')
1079-
1080-
for bad_date_string in bad_date_strings:
1081-
assert not parsing._does_string_look_like_datetime(bad_date_string)
1082-
1083-
good_date_strings = ('2012-01-01',
1084-
'01/01/2012',
1085-
'Mon Sep 16, 2013',
1086-
'01012012',
1087-
'0101',
1088-
'1-1', )
1089-
1090-
for good_date_string in good_date_strings:
1091-
assert parsing._does_string_look_like_datetime(good_date_string)
10921014

10931015
def test_parsers(self):
10941016

@@ -1148,8 +1070,8 @@ def test_parsers(self):
11481070
}
11491071

11501072
for date_str, expected in compat.iteritems(cases):
1151-
result1, _, _ = tools.parse_time_string(date_str,
1152-
yearfirst=yearfirst)
1073+
result1, _, _ = parsing.parse_time_string(date_str,
1074+
yearfirst=yearfirst)
11531075
result2 = to_datetime(date_str, yearfirst=yearfirst)
11541076
result3 = to_datetime([date_str], yearfirst=yearfirst)
11551077
# result5 is used below
@@ -1175,7 +1097,7 @@ def test_parsers(self):
11751097
assert result7 == expected
11761098

11771099
# NaT
1178-
result1, _, _ = tools.parse_time_string('NaT')
1100+
result1, _, _ = parsing.parse_time_string('NaT')
11791101
result2 = to_datetime('NaT')
11801102
result3 = Timestamp('NaT')
11811103
result4 = DatetimeIndex(['NaT'])[0]
@@ -1184,12 +1106,6 @@ def test_parsers(self):
11841106
assert result3 is tslib.NaT
11851107
assert result4 is tslib.NaT
11861108

1187-
def test_parsers_quarter_invalid(self):
1188-
1189-
cases = ['2Q 2005', '2Q-200A', '2Q-200', '22Q2005', '6Q-20', '2Q200.']
1190-
for case in cases:
1191-
pytest.raises(ValueError, tools.parse_time_string, case)
1192-
11931109
def test_parsers_dayfirst_yearfirst(self):
11941110
# OK
11951111
# 2.5.1 10-11-12 [dayfirst=0, yearfirst=0] -> 2012-10-11 00:00:00
@@ -1264,9 +1180,9 @@ def test_parsers_dayfirst_yearfirst(self):
12641180
yearfirst=yearfirst)
12651181
assert dateutil_result == expected
12661182

1267-
result1, _, _ = tools.parse_time_string(date_str,
1268-
dayfirst=dayfirst,
1269-
yearfirst=yearfirst)
1183+
result1, _, _ = parsing.parse_time_string(date_str,
1184+
dayfirst=dayfirst,
1185+
yearfirst=yearfirst)
12701186

12711187
# we don't support dayfirst/yearfirst here:
12721188
if not dayfirst and not yearfirst:
@@ -1289,7 +1205,7 @@ def test_parsers_timestring(self):
12891205
'9:05': (parse('9:05'), datetime(1, 1, 1, 9, 5))}
12901206

12911207
for date_str, (exp_now, exp_def) in compat.iteritems(cases):
1292-
result1, _, _ = tools.parse_time_string(date_str)
1208+
result1, _, _ = parsing.parse_time_string(date_str)
12931209
result2 = to_datetime(date_str)
12941210
result3 = to_datetime([date_str])
12951211
result4 = Timestamp(date_str)
@@ -1338,34 +1254,6 @@ def test_parsers_time(self):
13381254
assert isinstance(res, list)
13391255
assert res == expected_arr
13401256

1341-
def test_parsers_monthfreq(self):
1342-
cases = {'201101': datetime(2011, 1, 1, 0, 0),
1343-
'200005': datetime(2000, 5, 1, 0, 0)}
1344-
1345-
for date_str, expected in compat.iteritems(cases):
1346-
result1, _, _ = tools.parse_time_string(date_str, freq='M')
1347-
assert result1 == expected
1348-
1349-
def test_parsers_quarterly_with_freq(self):
1350-
msg = ('Incorrect quarterly string is given, quarter '
1351-
'must be between 1 and 4: 2013Q5')
1352-
with tm.assert_raises_regex(parsing.DateParseError, msg):
1353-
tools.parse_time_string('2013Q5')
1354-
1355-
# GH 5418
1356-
msg = ('Unable to retrieve month information from given freq: '
1357-
'INVLD-L-DEC-SAT')
1358-
with tm.assert_raises_regex(parsing.DateParseError, msg):
1359-
tools.parse_time_string('2013Q1', freq='INVLD-L-DEC-SAT')
1360-
1361-
cases = {('2013Q2', None): datetime(2013, 4, 1),
1362-
('2013Q2', 'A-APR'): datetime(2012, 8, 1),
1363-
('2013-Q2', 'A-DEC'): datetime(2013, 4, 1)}
1364-
1365-
for (date_str, freq), exp in compat.iteritems(cases):
1366-
result, _, _ = tools.parse_time_string(date_str, freq=freq)
1367-
assert result == exp
1368-
13691257
def test_parsers_timezone_minute_offsets_roundtrip(self):
13701258
# GH11708
13711259
base = to_datetime("2013-01-01 00:00:00")
@@ -1423,14 +1311,6 @@ def test_parsers_iso8601(self):
14231311

14241312

14251313
class TestArrayToDatetime(object):
1426-
1427-
def test_try_parse_dates(self):
1428-
arr = np.array(['5/1/2000', '6/1/2000', '7/1/2000'], dtype=object)
1429-
1430-
result = parsing.try_parse_dates(arr, dayfirst=True)
1431-
expected = [parse(d, dayfirst=True) for d in arr]
1432-
assert np.array_equal(result, expected)
1433-
14341314
def test_parsing_valid_dates(self):
14351315
arr = np.array(['01-01-2013', '01-02-2013'], dtype=object)
14361316
tm.assert_numpy_array_equal(

0 commit comments

Comments
 (0)