Skip to content

Commit 64f5917

Browse files
committed
MAINT: Replace datetools import in tests
1 parent d26363b commit 64f5917

17 files changed

+228
-212
lines changed

pandas/io/tests/test_sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from pandas import date_range, to_datetime, to_timedelta, Timestamp
3838
import pandas.compat as compat
3939
from pandas.compat import StringIO, range, lrange, string_types
40-
from pandas.core.datetools import format as date_format
40+
from pandas.tseries.tools import format as date_format
4141

4242
import pandas.io.sql as sql
4343
from pandas.io.sql import read_sql_table, read_sql_query

pandas/sparse/tests/test_frame.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pandas import Series, DataFrame, bdate_range, Panel
1010
from pandas.tseries.index import DatetimeIndex
11-
import pandas.core.datetools as datetools
11+
from pandas.tseries.offsets import BDay
1212
import pandas.util.testing as tm
1313
from pandas.compat import lrange
1414
from pandas import compat
@@ -850,8 +850,8 @@ def _check(frame, orig):
850850
exp = exp.to_sparse(frame.default_fill_value)
851851
tm.assert_frame_equal(shifted, exp)
852852

853-
shifted = frame.shift(2, freq=datetools.bday)
854-
exp = orig.shift(2, freq=datetools.bday)
853+
shifted = frame.shift(2, freq=BDay())
854+
exp = orig.shift(2, freq=BDay())
855855
exp = exp.to_sparse(frame.default_fill_value)
856856
tm.assert_frame_equal(shifted, exp)
857857

pandas/sparse/tests/test_series.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import pandas as pd
88

99
from pandas import Series, DataFrame, bdate_range
10-
from pandas.core.datetools import BDay
11-
import pandas.core.datetools as datetools
1210
from pandas.core.common import isnull
11+
from pandas.tseries.offsets import BDay
1312
import pandas.util.testing as tm
1413
from pandas.compat import range
1514
from pandas import compat
@@ -843,7 +842,7 @@ def test_shift(self):
843842
f = lambda s: s.shift(2, freq='B')
844843
_dense_series_compare(series, f)
845844

846-
f = lambda s: s.shift(2, freq=datetools.bday)
845+
f = lambda s: s.shift(2, freq=BDay())
847846
_dense_series_compare(series, f)
848847

849848
def test_shift_nan(self):

pandas/stats/tests/test_ols.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
from pandas import date_range, bdate_range
1818
from pandas.core.panel import Panel
19-
from pandas import DataFrame, Index, Series, notnull, datetools
19+
from pandas import DataFrame, Index, Series, notnull, offsets
2020
from pandas.stats.api import ols
2121
from pandas.stats.ols import _filter_data
2222
from pandas.stats.plm import NonPooledPanelOLS, PanelOLS
2323
from pandas.util.testing import (assert_almost_equal, assert_series_equal,
2424
assert_frame_equal, assertRaisesRegexp, slow)
2525
import pandas.util.testing as tm
2626
import pandas.compat as compat
27-
from .common import BaseTest
27+
from pandas.stats.tests.common import BaseTest
2828

2929
_have_statsmodels = True
3030
try:
@@ -898,22 +898,22 @@ class TestOLSFilter(tm.TestCase):
898898

899899
def setUp(self):
900900
date_index = date_range(datetime(2009, 12, 11), periods=3,
901-
freq=datetools.bday)
901+
freq=offsets.BDay())
902902
ts = Series([3, 1, 4], index=date_index)
903903
self.TS1 = ts
904904

905905
date_index = date_range(datetime(2009, 12, 11), periods=5,
906-
freq=datetools.bday)
906+
freq=offsets.BDay())
907907
ts = Series([1, 5, 9, 2, 6], index=date_index)
908908
self.TS2 = ts
909909

910910
date_index = date_range(datetime(2009, 12, 11), periods=3,
911-
freq=datetools.bday)
911+
freq=offsets.BDay())
912912
ts = Series([5, np.nan, 3], index=date_index)
913913
self.TS3 = ts
914914

915915
date_index = date_range(datetime(2009, 12, 11), periods=5,
916-
freq=datetools.bday)
916+
freq=offsets.BDay())
917917
ts = Series([np.nan, 5, 8, 9, 7], index=date_index)
918918
self.TS4 = ts
919919

pandas/tests/frame/test_indexing.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
date_range)
1818
import pandas as pd
1919

20+
from pandas.tseries.offsets import BDay
2021
from pandas.types.common import (is_float_dtype,
2122
is_integer,
2223
is_scalar)
@@ -2068,8 +2069,6 @@ def test_at_time_between_time_datetimeindex(self):
20682069
assert_frame_equal(result, df)
20692070

20702071
def test_xs(self):
2071-
from pandas.core.datetools import bday
2072-
20732072
idx = self.frame.index[5]
20742073
xs = self.frame.xs(idx)
20752074
for item, value in compat.iteritems(xs):
@@ -2090,7 +2089,7 @@ def test_xs(self):
20902089
self.assertEqual(xs['B'], '1')
20912090

20922091
with tm.assertRaises(KeyError):
2093-
self.tsframe.xs(self.tsframe.index[0] - bday)
2092+
self.tsframe.xs(self.tsframe.index[0] - BDay())
20942093

20952094
# xs get column
20962095
series = self.frame.xs('A', axis=1)
@@ -2772,3 +2771,9 @@ def test_transpose(self):
27722771
expected = DataFrame(self.df.values.T)
27732772
expected.index = ['A', 'B']
27742773
assert_frame_equal(result, expected)
2774+
2775+
2776+
if __name__ == '__main__':
2777+
import nose
2778+
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
2779+
exit=False)

pandas/tests/frame/test_timeseries.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from pandas import DataFrame, Series, Index, Timestamp, DatetimeIndex
1212
import pandas as pd
13-
import pandas.core.datetools as datetools
13+
import pandas.tseries.offsets as offsets
1414

1515
from pandas.util.testing import (assert_almost_equal,
1616
assert_series_equal,
@@ -136,14 +136,14 @@ def test_shift(self):
136136
assert_frame_equal(unshifted, self.tsframe)
137137

138138
# shift by DateOffset
139-
shiftedFrame = self.tsframe.shift(5, freq=datetools.BDay())
139+
shiftedFrame = self.tsframe.shift(5, freq=offsets.BDay())
140140
self.assertEqual(len(shiftedFrame), len(self.tsframe))
141141

142142
shiftedFrame2 = self.tsframe.shift(5, freq='B')
143143
assert_frame_equal(shiftedFrame, shiftedFrame2)
144144

145145
d = self.tsframe.index[0]
146-
shifted_d = d + datetools.BDay(5)
146+
shifted_d = d + offsets.BDay(5)
147147
assert_series_equal(self.tsframe.xs(d),
148148
shiftedFrame.xs(shifted_d), check_names=False)
149149

@@ -160,7 +160,7 @@ def test_shift(self):
160160
ps.ix[:-1, 0].values)
161161

162162
shifted2 = ps.shift(1, 'B')
163-
shifted3 = ps.shift(1, datetools.bday)
163+
shifted3 = ps.shift(1, offsets.BDay())
164164
assert_frame_equal(shifted2, shifted3)
165165
assert_frame_equal(ps, shifted2.shift(-1, 'B'))
166166

@@ -222,7 +222,7 @@ def test_tshift(self):
222222
shifted2 = ps.tshift(freq='B')
223223
assert_frame_equal(shifted, shifted2)
224224

225-
shifted3 = ps.tshift(freq=datetools.bday)
225+
shifted3 = ps.tshift(freq=offsets.BDay())
226226
assert_frame_equal(shifted, shifted3)
227227

228228
assertRaisesRegexp(ValueError, 'does not match', ps.tshift, freq='M')
@@ -297,7 +297,7 @@ def test_truncate_copy(self):
297297
self.assertFalse((self.tsframe.values[5:11] == 5).any())
298298

299299
def test_asfreq(self):
300-
offset_monthly = self.tsframe.asfreq(datetools.bmonthEnd)
300+
offset_monthly = self.tsframe.asfreq(offsets.BMonthEnd())
301301
rule_monthly = self.tsframe.asfreq('BM')
302302

303303
assert_almost_equal(offset_monthly['A'], rule_monthly['A'])
@@ -365,3 +365,9 @@ def test_operation_on_NaT(self):
365365
res = df.max()
366366
exp = pd.Series([pd.NaT], index=["foo"])
367367
tm.assert_series_equal(res, exp)
368+
369+
370+
if __name__ == '__main__':
371+
import nose
372+
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
373+
exit=False)

pandas/tests/series/test_indexing.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
from pandas.core.index import MultiIndex
1313
from pandas.core.indexing import IndexingError
1414
from pandas.tseries.index import Timestamp
15+
from pandas.tseries.offsets import BDay
1516
from pandas.tseries.tdi import Timedelta
1617

17-
import pandas.core.datetools as datetools
1818
from pandas.compat import lrange, range
1919
from pandas import compat
2020
from pandas.util.testing import assert_series_equal, assert_almost_equal
2121
import pandas.util.testing as tm
2222

23-
from .common import TestData
23+
from pandas.tests.series.common import TestData
2424

2525
JOIN_TYPES = ['inner', 'outer', 'left', 'right']
2626

@@ -153,7 +153,7 @@ def test_getitem_get(self):
153153
self.assertEqual(self.series[5], self.series.get(self.series.index[5]))
154154

155155
# missing
156-
d = self.ts.index[0] - datetools.bday
156+
d = self.ts.index[0] - BDay()
157157
self.assertRaises(KeyError, self.ts.__getitem__, d)
158158

159159
# None
@@ -321,7 +321,7 @@ def test_getitem_boolean_object(self):
321321

322322
def test_getitem_setitem_boolean_corner(self):
323323
ts = self.ts
324-
mask_shifted = ts.shift(1, freq=datetools.bday) > ts.median()
324+
mask_shifted = ts.shift(1, freq=BDay()) > ts.median()
325325

326326
# these used to raise...??
327327

@@ -1856,3 +1856,8 @@ def test_multilevel_preserve_name(self):
18561856
result2 = s.ix['foo']
18571857
self.assertEqual(result.name, s.name)
18581858
self.assertEqual(result2.name, s.name)
1859+
1860+
if __name__ == '__main__':
1861+
import nose
1862+
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
1863+
exit=False)

pandas/tests/series/test_timeseries.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
from pandas import Index, Series, date_range, NaT
99
from pandas.tseries.index import DatetimeIndex
10+
from pandas.tseries.offsets import BDay, BMonthEnd
1011
from pandas.tseries.tdi import TimedeltaIndex
1112

12-
import pandas.core.datetools as datetools
13-
1413
from pandas.util.testing import assert_series_equal, assert_almost_equal
1514
import pandas.util.testing as tm
1615

17-
from .common import TestData
16+
from pandas.tests.series.common import TestData
1817

1918

2019
class TestSeriesTimeSeries(TestData, tm.TestCase):
@@ -29,7 +28,7 @@ def test_shift(self):
2928
tm.assert_numpy_array_equal(unshifted.valid().values,
3029
self.ts.values[:-1])
3130

32-
offset = datetools.bday
31+
offset = BDay()
3332
shifted = self.ts.shift(1, freq=offset)
3433
unshifted = shifted.shift(-1, freq=offset)
3534

@@ -56,7 +55,7 @@ def test_shift(self):
5655
tm.assert_numpy_array_equal(unshifted.valid().values, ps.values[:-1])
5756

5857
shifted2 = ps.shift(1, 'B')
59-
shifted3 = ps.shift(1, datetools.bday)
58+
shifted3 = ps.shift(1, BDay())
6059
assert_series_equal(shifted2, shifted3)
6160
assert_series_equal(ps, shifted2.shift(-1, 'B'))
6261

@@ -66,7 +65,7 @@ def test_shift(self):
6665
shifted4 = ps.shift(1, freq='B')
6766
assert_series_equal(shifted2, shifted4)
6867

69-
shifted5 = ps.shift(1, freq=datetools.bday)
68+
shifted5 = ps.shift(1, freq=BDay())
7069
assert_series_equal(shifted5, shifted4)
7170

7271
# 32-bit taking
@@ -131,7 +130,7 @@ def test_tshift(self):
131130
shifted2 = ps.tshift(freq='B')
132131
assert_series_equal(shifted, shifted2)
133132

134-
shifted3 = ps.tshift(freq=datetools.bday)
133+
shifted3 = ps.tshift(freq=BDay())
135134
assert_series_equal(shifted, shifted3)
136135

137136
self.assertRaises(ValueError, ps.tshift, freq='M')
@@ -156,7 +155,7 @@ def test_tshift(self):
156155
self.assertRaises(ValueError, no_freq.tshift)
157156

158157
def test_truncate(self):
159-
offset = datetools.bday
158+
offset = BDay()
160159

161160
ts = self.ts[::3]
162161

@@ -417,8 +416,8 @@ def test_asfreq(self):
417416
monthly_ts = daily_ts.asfreq('BM')
418417
self.assert_series_equal(monthly_ts, ts)
419418

420-
daily_ts = ts.asfreq(datetools.bday)
421-
monthly_ts = daily_ts.asfreq(datetools.bmonthEnd)
419+
daily_ts = ts.asfreq(BDay())
420+
monthly_ts = daily_ts.asfreq(BMonthEnd())
422421
self.assert_series_equal(monthly_ts, ts)
423422

424423
result = ts[:0].asfreq('M')
@@ -561,3 +560,9 @@ def test_empty_series_ops(self):
561560
assert_series_equal(a, a - b)
562561
assert_series_equal(a, b + a)
563562
self.assertRaises(TypeError, lambda x, y: x - y, b, a)
563+
564+
565+
if __name__ == '__main__':
566+
import nose
567+
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
568+
exit=False)

pandas/tests/test_panel.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import pandas as pd
1111

1212
from pandas.types.common import is_float_dtype
13-
from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
14-
from pandas.core.datetools import bday
13+
from pandas import (Series, DataFrame, Index, date_range, isnull, notnull,
14+
pivot, MultiIndex)
1515
from pandas.core.nanops import nanall, nanany
1616
from pandas.core.panel import Panel
1717
from pandas.core.series import remove_na
@@ -20,6 +20,7 @@
2020
from pandas import compat
2121
from pandas.compat import range, lrange, StringIO, OrderedDict, signature
2222

23+
from pandas.tseries.offsets import BDay, MonthEnd
2324
from pandas.util.testing import (assert_panel_equal, assert_frame_equal,
2425
assert_series_equal, assert_almost_equal,
2526
ensure_clean, assertRaisesRegexp,
@@ -500,11 +501,9 @@ def test_setitem(self):
500501
p[0] = np.random.randn(4, 2)
501502

502503
def test_setitem_ndarray(self):
503-
from pandas import date_range, datetools
504-
505504
timeidx = date_range(start=datetime(2009, 1, 1),
506505
end=datetime(2009, 12, 31),
507-
freq=datetools.MonthEnd())
506+
freq=MonthEnd())
508507
lons_coarse = np.linspace(-177.5, 177.5, 72)
509508
lats_coarse = np.linspace(-87.5, 87.5, 36)
510509
P = Panel(items=timeidx, major_axis=lons_coarse,
@@ -542,7 +541,7 @@ def test_major_xs(self):
542541
self.assertEqual(result.name, 'ItemA')
543542

544543
# not contained
545-
idx = self.panel.major_axis[0] - bday
544+
idx = self.panel.major_axis[0] - BDay()
546545
self.assertRaises(Exception, self.panel.major_xs, idx)
547546

548547
def test_major_xs_mixed(self):
@@ -1878,7 +1877,7 @@ def test_tshift(self):
18781877
shifted2 = ps.tshift(freq='B')
18791878
assert_panel_equal(shifted, shifted2)
18801879

1881-
shifted3 = ps.tshift(freq=bday)
1880+
shifted3 = ps.tshift(freq=BDay())
18821881
assert_panel_equal(shifted, shifted3)
18831882

18841883
assertRaisesRegexp(ValueError, 'does not match', ps.tshift, freq='M')

pandas/tests/test_panel4d.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
from pandas.types.common import is_float_dtype
1010
from pandas import Series, Index, isnull, notnull
11-
from pandas.core.datetools import bday
1211
from pandas.core.panel import Panel
1312
from pandas.core.panel4d import Panel4D
1413
from pandas.core.series import remove_na
14+
from pandas.tseries.offsets import BDay
1515

1616
from pandas.util.testing import (assert_panel_equal,
1717
assert_panel4d_equal,
@@ -479,7 +479,7 @@ def test_major_xs(self):
479479
ref.xs(idx), check_names=False)
480480

481481
# not contained
482-
idx = self.panel4d.major_axis[0] - bday
482+
idx = self.panel4d.major_axis[0] - BDay()
483483
self.assertRaises(Exception, self.panel4d.major_xs, idx)
484484

485485
def test_major_xs_mixed(self):

0 commit comments

Comments
 (0)