|
1 | 1 | # pylint: disable-msg=E1101,W0612 |
2 | 2 | import calendar |
3 | | -from datetime import datetime, time, timedelta |
4 | | -import sys |
5 | 3 | import operator |
| 4 | +import sys |
6 | 5 | import warnings |
| 6 | +from datetime import datetime, time, timedelta |
| 7 | +from numpy.random import rand |
| 8 | +from numpy.testing.decorators import slow |
| 9 | + |
7 | 10 | import nose |
8 | 11 | import numpy as np |
9 | | -import pandas.tseries.frequencies as frequencies |
| 12 | +import pandas.index as _index |
10 | 13 | import pandas.lib as lib |
11 | 14 | import pandas.tslib as tslib |
12 | | -import pandas.index as _index |
13 | | -import pandas as pd |
14 | | -from pandas import (Index, Series, DataFrame, isnull, date_range, Timestamp, |
15 | | - Period, DatetimeIndex, Int64Index, to_datetime, |
16 | | - bdate_range, Float64Index, NaT, timedelta_range, Timedelta) |
17 | 15 |
|
18 | | -from pandas.compat.numpy_compat import np_datetime64_compat |
| 16 | +import pandas as pd |
| 17 | +import pandas.compat as compat |
| 18 | +import pandas.core.common as com |
19 | 19 | import pandas.core.datetools as datetools |
| 20 | +import pandas.tseries.frequencies as frequencies |
20 | 21 | import pandas.tseries.offsets as offsets |
21 | 22 | import pandas.tseries.tools as tools |
22 | | - |
23 | | - |
24 | | -from pandas.util.testing import assert_series_equal, assert_almost_equal,\ |
25 | | - _skip_if_has_locale |
26 | 23 | import pandas.util.testing as tm |
27 | | - |
28 | | -from pandas.tslib import iNaT |
29 | | - |
| 24 | +from pandas import ( |
| 25 | + Index, Series, DataFrame, isnull, date_range, Timestamp, Period, |
| 26 | + DatetimeIndex, Int64Index, to_datetime, bdate_range, Float64Index, |
| 27 | + NaT, timedelta_range, Timedelta, _np_version_under1p8, concat, |
| 28 | + PeriodIndex) |
30 | 29 | from pandas.compat import range, long, StringIO, lrange, lmap, zip, product |
31 | | -from numpy.random import rand |
32 | | -from pandas.util.testing import assert_frame_equal |
| 30 | +from pandas.compat.numpy_compat import np_datetime64_compat |
33 | 31 | from pandas.core.common import PerformanceWarning |
34 | | -import pandas.compat as compat |
35 | | -import pandas.core.common as com |
36 | | -from pandas import concat |
37 | | -from pandas import _np_version_under1p8 |
38 | | - |
39 | | -from numpy.testing.decorators import slow |
| 32 | +from pandas.tslib import iNaT |
| 33 | +from pandas.util.testing import ( |
| 34 | + assert_frame_equal, assert_series_equal, assert_almost_equal, |
| 35 | + _skip_if_has_locale) |
40 | 36 |
|
41 | 37 | randn = np.random.randn |
42 | 38 |
|
@@ -1247,23 +1243,6 @@ def test_asfreq_keep_index_name(self): |
1247 | 1243 | tm.assert_equal(index_name, df.index.name) |
1248 | 1244 | tm.assert_equal(index_name, df.asfreq('10D').index.name) |
1249 | 1245 |
|
1250 | | - def test_asfreq_resample_set_correct_freq(self): |
1251 | | - # GH5613 |
1252 | | - # we test if .asfreq() and .resample() set the correct value for .freq |
1253 | | - df = pd.DataFrame({'date': ["2012-01-01", "2012-01-02", "2012-01-03"], |
1254 | | - 'col': [1, 2, 3]}) |
1255 | | - df = df.set_index(pd.to_datetime(df.date)) |
1256 | | - |
1257 | | - # testing the settings before calling .asfreq() and .resample() |
1258 | | - self.assertEqual(df.index.freq, None) |
1259 | | - self.assertEqual(df.index.inferred_freq, 'D') |
1260 | | - |
1261 | | - # does .asfreq() set .freq correctly? |
1262 | | - self.assertEqual(df.asfreq('D').index.freq, 'D') |
1263 | | - |
1264 | | - # does .resample() set .freq correctly? |
1265 | | - self.assertEqual(df.resample('D').asfreq().index.freq, 'D') |
1266 | | - |
1267 | 1246 | def test_promote_datetime_date(self): |
1268 | 1247 | rng = date_range('1/1/2000', periods=20) |
1269 | 1248 | ts = Series(np.random.randn(20), index=rng) |
@@ -2246,69 +2225,22 @@ def test_concat_datetime_datetime64_frame(self): |
2246 | 2225 | # it works! |
2247 | 2226 | pd.concat([df1, df2_obj]) |
2248 | 2227 |
|
2249 | | - def test_period_resample(self): |
2250 | | - # GH3609 |
2251 | | - s = Series(range(100), index=date_range( |
2252 | | - '20130101', freq='s', periods=100), dtype='float') |
2253 | | - s[10:30] = np.nan |
2254 | | - expected = Series([34.5, 79.5], index=[Period( |
2255 | | - '2013-01-01 00:00', 'T'), Period('2013-01-01 00:01', 'T')]) |
2256 | | - result = s.to_period().resample('T', kind='period').mean() |
2257 | | - assert_series_equal(result, expected) |
2258 | | - result2 = s.resample('T', kind='period').mean() |
2259 | | - assert_series_equal(result2, expected) |
2260 | | - |
2261 | | - def test_period_resample_with_local_timezone_pytz(self): |
2262 | | - # GH5430 |
2263 | | - tm._skip_if_no_pytz() |
2264 | | - import pytz |
2265 | | - |
2266 | | - local_timezone = pytz.timezone('America/Los_Angeles') |
2267 | | - |
2268 | | - start = datetime(year=2013, month=11, day=1, hour=0, minute=0, |
2269 | | - tzinfo=pytz.utc) |
2270 | | - # 1 day later |
2271 | | - end = datetime(year=2013, month=11, day=2, hour=0, minute=0, |
2272 | | - tzinfo=pytz.utc) |
2273 | | - |
2274 | | - index = pd.date_range(start, end, freq='H') |
2275 | | - |
2276 | | - series = pd.Series(1, index=index) |
2277 | | - series = series.tz_convert(local_timezone) |
2278 | | - result = series.resample('D', kind='period').mean() |
2279 | | - |
2280 | | - # Create the expected series |
2281 | | - # Index is moved back a day with the timezone conversion from UTC to |
2282 | | - # Pacific |
2283 | | - expected_index = (pd.period_range(start=start, end=end, freq='D') - 1) |
2284 | | - expected = pd.Series(1, index=expected_index) |
2285 | | - assert_series_equal(result, expected) |
2286 | | - |
2287 | | - def test_period_resample_with_local_timezone_dateutil(self): |
2288 | | - # GH5430 |
2289 | | - tm._skip_if_no_dateutil() |
2290 | | - import dateutil |
2291 | | - |
2292 | | - local_timezone = 'dateutil/America/Los_Angeles' |
2293 | | - |
2294 | | - start = datetime(year=2013, month=11, day=1, hour=0, minute=0, |
2295 | | - tzinfo=dateutil.tz.tzutc()) |
2296 | | - # 1 day later |
2297 | | - end = datetime(year=2013, month=11, day=2, hour=0, minute=0, |
2298 | | - tzinfo=dateutil.tz.tzutc()) |
| 2228 | + def test_asfreq_resample_set_correct_freq(self): |
| 2229 | + # GH5613 |
| 2230 | + # we test if .asfreq() and .resample() set the correct value for .freq |
| 2231 | + df = pd.DataFrame({'date': ["2012-01-01", "2012-01-02", "2012-01-03"], |
| 2232 | + 'col': [1, 2, 3]}) |
| 2233 | + df = df.set_index(pd.to_datetime(df.date)) |
2299 | 2234 |
|
2300 | | - index = pd.date_range(start, end, freq='H') |
| 2235 | + # testing the settings before calling .asfreq() and .resample() |
| 2236 | + self.assertEqual(df.index.freq, None) |
| 2237 | + self.assertEqual(df.index.inferred_freq, 'D') |
2301 | 2238 |
|
2302 | | - series = pd.Series(1, index=index) |
2303 | | - series = series.tz_convert(local_timezone) |
2304 | | - result = series.resample('D', kind='period').mean() |
| 2239 | + # does .asfreq() set .freq correctly? |
| 2240 | + self.assertEqual(df.asfreq('D').index.freq, 'D') |
2305 | 2241 |
|
2306 | | - # Create the expected series |
2307 | | - # Index is moved back a day with the timezone conversion from UTC to |
2308 | | - # Pacific |
2309 | | - expected_index = (pd.period_range(start=start, end=end, freq='D') - 1) |
2310 | | - expected = pd.Series(1, index=expected_index) |
2311 | | - assert_series_equal(result, expected) |
| 2242 | + # does .resample() set .freq correctly? |
| 2243 | + self.assertEqual(df.resample('D').asfreq().index.freq, 'D') |
2312 | 2244 |
|
2313 | 2245 | def test_pickle(self): |
2314 | 2246 |
|
|
0 commit comments