windng
Check-in [5be8ea71ab]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:pandas.TimeSeries is deprecated. Fixes [3d4d407b06].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5be8ea71abcf592d47974b931d35f0e156f7e51a
User & Date: goyo 2015-10-19 13:30:44
References
2015-10-19
13:32 Closed ticket [3d4d407b06]: pandas.Timestamp is deprecated plus 5 other changes artifact: a84003c7e1 user: goyo
Context
2015-10-20
06:57
Drop support for pandas <= 0.15.1 in windng.io. check-in: b0ca1456a2 user: goyo tags: trunk
2015-10-19
13:30
pandas.TimeSeries is deprecated. Fixes [3d4d407b06]. check-in: 5be8ea71ab user: goyo tags: trunk
13:05
pandas.testing.assert_array_equal() is not available anymore. check-in: 27b68805f6 user: goyo tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/test_extremes.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# test_extremes.py
#
# Copyright 2013-2014 Goyo <goyodiaz@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
................................................................................
import windng.extremes as extremes


class Test_mis(unittest.TestCase):
    def test_mis(self):
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.mis(s, threshold=16, separation=4)
        np.testing.assert_array_equal(result, [21, 19, 20])

        # Invalid values do not affect the result.
        speed = np.r_[[np.nan], speed[:10], 3*[np.nan], speed[10:], 4*[np.nan]]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.mis(s, threshold=16, separation=4)
        np.testing.assert_array_equal(result, [21, 19, 20])


class Test_vref_sg(unittest.TestCase):
    def test_vref_sg(self):
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.vref_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)

        # Exponent = 2
        result = extremes.vref_sg(s, threshold=16, separation=4, exponent=2)
        self.assertAlmostEqual(result.vref, 28.683620447883367)

        # Invalid values do not affect the result.
        speed = np.r_[[np.nan], speed[:10], 3*[np.nan], speed[10:], 4*[np.nan]]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.vref_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)


class Test_mis_sg(unittest.TestCase):
    def test_mis_sg(self):
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.mis_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)

        # Exponent = 2
        result = extremes.mis_sg(s, threshold=16, separation=4, exponent=2)
        self.assertAlmostEqual(result.vref, 28.683620447883367)

        # Invalid values do not affect the result.
        speed = np.r_[[np.nan], speed[:10], 3*[np.nan], speed[10:], 4*[np.nan]]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.mis_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)


class Test_MISResult(unittest.TestCase):
    def test_to_text(self):
        # Exact output varies with python version (weird).
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.TimeSeries(speed, index=dates)
        result = extremes.mis_sg(s, threshold=16, separation=4)
        result = result.to_string().split('\n')
        self.assertEqual(result[0], 'Options:')
        self.assertEqual(result[1], 'Storm threshold: 16')
        self.assertEqual(result[2], 'Separation: 4')
        self.assertEqual(result[3], '')
        self.assertEqual(result[4], 'Result:')





|







 







|






|








|










|








|










|









|







1
2
3
4
5
6
7
8
9
10
11
12
13
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# test_extremes.py
#
# Copyright 2013-2015 Goyo <goyodiaz@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
................................................................................
import windng.extremes as extremes


class Test_mis(unittest.TestCase):
    def test_mis(self):
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.mis(s, threshold=16, separation=4)
        np.testing.assert_array_equal(result, [21, 19, 20])

        # Invalid values do not affect the result.
        speed = np.r_[[np.nan], speed[:10], 3*[np.nan], speed[10:], 4*[np.nan]]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.mis(s, threshold=16, separation=4)
        np.testing.assert_array_equal(result, [21, 19, 20])


class Test_vref_sg(unittest.TestCase):
    def test_vref_sg(self):
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.vref_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)

        # Exponent = 2
        result = extremes.vref_sg(s, threshold=16, separation=4, exponent=2)
        self.assertAlmostEqual(result.vref, 28.683620447883367)

        # Invalid values do not affect the result.
        speed = np.r_[[np.nan], speed[:10], 3*[np.nan], speed[10:], 4*[np.nan]]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.vref_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)


class Test_mis_sg(unittest.TestCase):
    def test_mis_sg(self):
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.mis_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)

        # Exponent = 2
        result = extremes.mis_sg(s, threshold=16, separation=4, exponent=2)
        self.assertAlmostEqual(result.vref, 28.683620447883367)

        # Invalid values do not affect the result.
        speed = np.r_[[np.nan], speed[:10], 3*[np.nan], speed[10:], 4*[np.nan]]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.mis_sg(s, threshold=16, separation=4)
        self.assertAlmostEqual(result.vref, 30.541681394847167)


class Test_MISResult(unittest.TestCase):
    def test_to_text(self):
        # Exact output varies with python version (weird).
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        s = pd.Series(speed, index=dates)
        result = extremes.mis_sg(s, threshold=16, separation=4)
        result = result.to_string().split('\n')
        self.assertEqual(result[0], 'Options:')
        self.assertEqual(result[1], 'Storm threshold: 16')
        self.assertEqual(result[2], 'Separation: 4')
        self.assertEqual(result[3], '')
        self.assertEqual(result[4], 'Result:')

Changes to test/test_extremes_app.py.

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
        w = extremes_app.DataFrame()
        with self.assertRaises(ValueError):
            w.load(sample)
        w.destroy()

    def test_refresh_generate_event(self):
        fname = 'samplename'
        data = pd.TimeSeries(
            np.random.randn(10),
            index=pd.date_range('2000-01-01', periods=10, freq='10T')
        )

        def data_changed_cb(event):
            self.data_changed = True

................................................................................

class TestWindExtremesFrame(unittest.TestCase):
    pass
    def test_data_changed_triggers_results_refresh(self):
        fname = 'samplename'
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        data = pd.TimeSeries(speed, index=dates)

        w = extremes_app.WindExtremesFrame()
        w.winfo_toplevel().withdraw()
        w.data_frame.refresh(fname, data)
        # assert w gets a refresh.
        self.assertAlmostEqual(w.result_frame.mis_result.vref, 28.534368908630434)
        w.winfo_toplevel().destroy()

    def test_export(self):
        fname = '\u2013'
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        data = pd.TimeSeries(speed, index=dates)

        w = extremes_app.WindExtremesFrame()
        w.winfo_toplevel().withdraw()
        w.data_frame.refresh(fname, data)
        w.export(os.devnull)
        w.winfo_toplevel().destroy()








|







 







|












|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
        w = extremes_app.DataFrame()
        with self.assertRaises(ValueError):
            w.load(sample)
        w.destroy()

    def test_refresh_generate_event(self):
        fname = 'samplename'
        data = pd.Series(
            np.random.randn(10),
            index=pd.date_range('2000-01-01', periods=10, freq='10T')
        )

        def data_changed_cb(event):
            self.data_changed = True

................................................................................

class TestWindExtremesFrame(unittest.TestCase):
    pass
    def test_data_changed_triggers_results_refresh(self):
        fname = 'samplename'
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        data = pd.Series(speed, index=dates)

        w = extremes_app.WindExtremesFrame()
        w.winfo_toplevel().withdraw()
        w.data_frame.refresh(fname, data)
        # assert w gets a refresh.
        self.assertAlmostEqual(w.result_frame.mis_result.vref, 28.534368908630434)
        w.winfo_toplevel().destroy()

    def test_export(self):
        fname = '\u2013'
        speed = [13, 21, 13, 8, 6, 8, 11, 11, 11, 17, 14, 19, 10, 7, 9, 10, 13, 14, 13, 20]
        dates = pd.date_range('2000-01-01', periods=len(speed), freq='12H')
        data = pd.Series(speed, index=dates)

        w = extremes_app.WindExtremesFrame()
        w.winfo_toplevel().withdraw()
        w.data_frame.refresh(fname, data)
        w.export(os.devnull)
        w.winfo_toplevel().destroy()

Changes to test/test_oldflags.py.

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
        """Run after every test in this class."""
        pass

    def test_time_segments(self):
        """Test function time_segments."""
        data = [False] + [True] * 2 + [False] * 3 + [True] * 4
        index = pd.date_range(start='2000-01-01', periods=len(data), freq='10T')
        cond = pd.TimeSeries(data=data, index=index)
        result = flags.time_segments(cond)
        expected_start = pd.DatetimeIndex(
            ['2000-01-01 00:10:00', '2000-01-01 01:00:00',]
        )
        expected_end = pd.DatetimeIndex(
            ['2000-01-01 00:20:00', '2000-01-01 01:30:00']
        )
................................................................................
        flag = flags.Flag(target=target, segments=segments, desc=desc)
        self.assertEqual(flag.target, target)
        self.assertEqual(flag.segments, segments)
        self.assertEqual(flag.desc, desc)

    def test_flagged(self):
        """Test method Flag.flagged."""
        target = pd.TimeSeries(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        start = pd.DatetimeIndex(['2000-01-01 00:00', '2000-01-01 00:30'])
        end = pd.DatetimeIndex(['2000-01-01 00:10', '2000-01-01 00:30'])
        segments = pd.DataFrame(
            data=[start, end],
................................................................................
        )
        expected_values = [0, 1, 3]
        self.assertTrue((result.index == expected_index).all())
        self.assertTrue((result.values == expected_values).all())

    def test_flagged_empty(self):
        """Test method Flag.flagged with 0 segments."""
        target = pd.TimeSeries(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        segments = pd.DataFrame(
            data=np.array([], dtype=object).reshape(0, 2),
            index=[],
            columns=['start', 'end']
................................................................................
    def test_from_rule_cr(self):
        """Test method Flag.from_rule with function contiguous_regions."""
        target = 0
        func = flags.time_segments
        desc = 'Sample rule'
        data = [False] + [True] * 2 + [False] * 3 + [True] * 4
        index = pd.date_range(start='2000-01-01', periods=len(data), freq='10T')
        args = [pd.TimeSeries(data=data, index=index)]
        rule = flags.FlagRule(target=target, func=func, args=args, desc=desc)
        flag = flags.Flag.from_rule(rule)
        self.assertTrue(isinstance(flag, flags.Flag))
        self.assertEqual(flag.target, target)
        expected_start = pd.DatetimeIndex(
            ['2000-01-01 00:10:00', '2000-01-01 01:00:00',]
        )
................................................................................
        self.assertTrue((flag.segments.start == expected_start).all())
        self.assertTrue((flag.segments.end == expected_end).all())
        self.assertTrue((flag.segments.index == [0, 1]).all())
        self.assertEqual(flag.desc, desc)

    def test_plot(self):
        """Test method Flag.plot."""
        target = pd.TimeSeries(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        start = pd.DatetimeIndex(['2000-01-01 00:00', '2000-01-01 00:30'])
        end = pd.DatetimeIndex(['2000-01-01 00:10', '2000-01-01 00:30'])
        segments = pd.DataFrame(
            data=[start, end],
................................................................................
        flag = flags.Flag(target=target, segments=segments, desc=desc)
        result = flag.plot()
        self.assertTrue(result is plt.gca())
        plt.close()

    def test_plot_grid(self):
        """Test method Flag.plot with argument grid."""
        target = pd.TimeSeries(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        start = pd.DatetimeIndex(['2000-01-01 00:00', '2000-01-01 00:30'])
        end = pd.DatetimeIndex(['2000-01-01 00:10', '2000-01-01 00:30'])
        segments = pd.DataFrame(
            data=[start, end],







|







 







|







 







|







 







|







 







|







 







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
        """Run after every test in this class."""
        pass

    def test_time_segments(self):
        """Test function time_segments."""
        data = [False] + [True] * 2 + [False] * 3 + [True] * 4
        index = pd.date_range(start='2000-01-01', periods=len(data), freq='10T')
        cond = pd.Series(data=data, index=index)
        result = flags.time_segments(cond)
        expected_start = pd.DatetimeIndex(
            ['2000-01-01 00:10:00', '2000-01-01 01:00:00',]
        )
        expected_end = pd.DatetimeIndex(
            ['2000-01-01 00:20:00', '2000-01-01 01:30:00']
        )
................................................................................
        flag = flags.Flag(target=target, segments=segments, desc=desc)
        self.assertEqual(flag.target, target)
        self.assertEqual(flag.segments, segments)
        self.assertEqual(flag.desc, desc)

    def test_flagged(self):
        """Test method Flag.flagged."""
        target = pd.Series(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        start = pd.DatetimeIndex(['2000-01-01 00:00', '2000-01-01 00:30'])
        end = pd.DatetimeIndex(['2000-01-01 00:10', '2000-01-01 00:30'])
        segments = pd.DataFrame(
            data=[start, end],
................................................................................
        )
        expected_values = [0, 1, 3]
        self.assertTrue((result.index == expected_index).all())
        self.assertTrue((result.values == expected_values).all())

    def test_flagged_empty(self):
        """Test method Flag.flagged with 0 segments."""
        target = pd.Series(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        segments = pd.DataFrame(
            data=np.array([], dtype=object).reshape(0, 2),
            index=[],
            columns=['start', 'end']
................................................................................
    def test_from_rule_cr(self):
        """Test method Flag.from_rule with function contiguous_regions."""
        target = 0
        func = flags.time_segments
        desc = 'Sample rule'
        data = [False] + [True] * 2 + [False] * 3 + [True] * 4
        index = pd.date_range(start='2000-01-01', periods=len(data), freq='10T')
        args = [pd.Series(data=data, index=index)]
        rule = flags.FlagRule(target=target, func=func, args=args, desc=desc)
        flag = flags.Flag.from_rule(rule)
        self.assertTrue(isinstance(flag, flags.Flag))
        self.assertEqual(flag.target, target)
        expected_start = pd.DatetimeIndex(
            ['2000-01-01 00:10:00', '2000-01-01 01:00:00',]
        )
................................................................................
        self.assertTrue((flag.segments.start == expected_start).all())
        self.assertTrue((flag.segments.end == expected_end).all())
        self.assertTrue((flag.segments.index == [0, 1]).all())
        self.assertEqual(flag.desc, desc)

    def test_plot(self):
        """Test method Flag.plot."""
        target = pd.Series(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        start = pd.DatetimeIndex(['2000-01-01 00:00', '2000-01-01 00:30'])
        end = pd.DatetimeIndex(['2000-01-01 00:10', '2000-01-01 00:30'])
        segments = pd.DataFrame(
            data=[start, end],
................................................................................
        flag = flags.Flag(target=target, segments=segments, desc=desc)
        result = flag.plot()
        self.assertTrue(result is plt.gca())
        plt.close()

    def test_plot_grid(self):
        """Test method Flag.plot with argument grid."""
        target = pd.Series(
            data=range(5),
            index=pd.date_range(start='2000-01-01', periods=5, freq='10T')
        )
        start = pd.DatetimeIndex(['2000-01-01 00:00', '2000-01-01 00:30'])
        end = pd.DatetimeIndex(['2000-01-01 00:10', '2000-01-01 00:30'])
        segments = pd.DataFrame(
            data=[start, end],

Changes to test/test_wind.py.

428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
...
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
class Test_downsample(unittest.TestCase):
    """Test function downsample."""
    def test_downsample(self):
        """Test function downsample."""
        index = pd.date_range('2000-01-01', periods=2000, freq='10T')
        x = np.arange(2000)
        y = np.sin(x/100) + 1
        series = pd.TimeSeries(y, index=index)
        series['2000-01-10 00:00': '2000-01-11 11:50'] = np.nan
        daily = wind.downsample(series, freq='D')

        expected = pd.PeriodIndex([
            '2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
            '2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08',
            '2000-01-09', '2000-01-10', '2000-01-11', '2000-01-12',
................................................................................
        """Test function downsample (ten-minutely to hourly)."""
        index = pd.date_range('2000-01-01', periods=15, freq='10T')
        x = [
            5.21848322, 4.14661940, 2.64555612, 7.74233689, 4.56150332,
            5.68433949, 0.18789800, 6.17635497, 6.12095723, 6.16933997,
            9.43748079, 6.81820299, 3.59507901, 4.37031954, 6.97631196
        ]
        series = pd.TimeSeries(x, index=index)
        hourly = wind.downsample(series, freq='H')
        hourly_ts = wind.downsample(series, freq='H', kind='timestamp')

        expected = pd.period_range(start='2000-01-01 00:00', periods=3,
            freq='H')
        pdt.assert_index_equal(hourly.index, expected)
        expected = pd.date_range(start='2000-01-01 00:00', periods=3,
................................................................................

    def test_downsample_20H_A(self):
        """Test function downsample (twenty-hourly to annual)."""
        index = pd.date_range('2000-12-03 10:30', periods=474, freq='20H')
        seed = np.int64(201305122051).astype(np.uint32)
        np.random.seed(seed)
        x = 10 * np.random.rand(len(index))
        series = pd.TimeSeries(x, index=index)
        annual = wind.downsample(series, freq='A')
        expected = pd.period_range(start='2000', periods=3, freq='A')
        self.assertListEqual(list(annual.index), list(expected))
        expected = [4.79807079665, 5.03872330141, 1.95572582748]
        self.assertTrue(np.allclose(annual['mean'], expected))
        self.assertEqual(list(annual['count']), [35, 438, 1])
        self.assertEqual(list(annual['possible']), [439.2, 438, 438])
................................................................................

    def test_downsample_20H_Q(self):
        """Test function downsample (twenty-hourly to quarterly)."""
        index = pd.date_range('2000-12-03 10:30', periods=474, freq='20H')
        seed = np.int64(201305122121).astype(np.uint32)
        np.random.seed(seed)
        x = 10 * np.random.rand(len(index))
        series = pd.TimeSeries(x, index=index)
        quarterly = wind.downsample(series, freq='Q')
        expected = pd.period_range(start='2000Q4', periods=6, freq='Q')
        self.assertListEqual(list(quarterly.index), list(expected))
        expected = [
            5.20769986209, 5.21883011776, 4.64734627795,
            4.76715486655, 5.2060181349, 0.348959422085
        ]
................................................................................
        self.assertTrue(np.allclose(result['B']['rec_rate'], [1, 1, 1, 0.333333]))
        self.assertTrue(np.allclose(result['possible'], [3, 3, 3, 3]))


class Test_downsample_dir(unittest.TestCase):
    def test_downsample_dir(self):
        index = pd.date_range('2000-01-01', freq='10T', periods=30, name='timestamp')
        d = pd.TimeSeries([
            206, 340, 265, 199, 107, 169, 286,  18, 143, 140, 288, 126,
            345, 336, 103, 132, 119, 282, 154, 223,  59, 174, 222, 351,
            145, 313, 101,  66, 135, 132
        ], index=index)
        s = pd.TimeSeries([
            8.46166109,  6.66049966,  2.28832706,  0.69091534,  8.86574959,
            8.40290133,  0.79775699,  8.50917337,  0.66806117,  5.00115906,
            9.37854938,  0.64840152,  7.0377572 ,  7.34612126,  9.78337364,
            2.2478703 ,  1.59568135,  6.08521493,  4.48504165,  7.61680989,
            2.37197815,  4.02293607,  9.84346178,  1.81458986,  0.23772917,
            6.95868632,  0.17872466,  3.77935404,  9.77546444,  9.89224031
        ], index=index)
................................................................................
class Test_monthly_means(unittest.TestCase):
    """Test function monthly_means."""
    def test_monthly_means(self):
        """Test function monthly_means."""
        index = pd.date_range('2000-01-01', periods=2000, freq='6H')
        x = np.arange(2000)
        y = np.sin(x/100) + 1
        df = pd.TimeSeries(y, index=index)
        df['2000-01-15 00:00': '2000-03-15 00:00'] = np.nan
        monthly = wind.monthly_means(df)

        self.assertEqual(len(monthly), 17)
        self.assertEqual(monthly.index.freq, 'M')

        expected = pd.PeriodIndex(







|







 







|







 







|







 







|







 







|




|







 







|







428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
...
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
class Test_downsample(unittest.TestCase):
    """Test function downsample."""
    def test_downsample(self):
        """Test function downsample."""
        index = pd.date_range('2000-01-01', periods=2000, freq='10T')
        x = np.arange(2000)
        y = np.sin(x/100) + 1
        series = pd.Series(y, index=index)
        series['2000-01-10 00:00': '2000-01-11 11:50'] = np.nan
        daily = wind.downsample(series, freq='D')

        expected = pd.PeriodIndex([
            '2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
            '2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08',
            '2000-01-09', '2000-01-10', '2000-01-11', '2000-01-12',
................................................................................
        """Test function downsample (ten-minutely to hourly)."""
        index = pd.date_range('2000-01-01', periods=15, freq='10T')
        x = [
            5.21848322, 4.14661940, 2.64555612, 7.74233689, 4.56150332,
            5.68433949, 0.18789800, 6.17635497, 6.12095723, 6.16933997,
            9.43748079, 6.81820299, 3.59507901, 4.37031954, 6.97631196
        ]
        series = pd.Series(x, index=index)
        hourly = wind.downsample(series, freq='H')
        hourly_ts = wind.downsample(series, freq='H', kind='timestamp')

        expected = pd.period_range(start='2000-01-01 00:00', periods=3,
            freq='H')
        pdt.assert_index_equal(hourly.index, expected)
        expected = pd.date_range(start='2000-01-01 00:00', periods=3,
................................................................................

    def test_downsample_20H_A(self):
        """Test function downsample (twenty-hourly to annual)."""
        index = pd.date_range('2000-12-03 10:30', periods=474, freq='20H')
        seed = np.int64(201305122051).astype(np.uint32)
        np.random.seed(seed)
        x = 10 * np.random.rand(len(index))
        series = pd.Series(x, index=index)
        annual = wind.downsample(series, freq='A')
        expected = pd.period_range(start='2000', periods=3, freq='A')
        self.assertListEqual(list(annual.index), list(expected))
        expected = [4.79807079665, 5.03872330141, 1.95572582748]
        self.assertTrue(np.allclose(annual['mean'], expected))
        self.assertEqual(list(annual['count']), [35, 438, 1])
        self.assertEqual(list(annual['possible']), [439.2, 438, 438])
................................................................................

    def test_downsample_20H_Q(self):
        """Test function downsample (twenty-hourly to quarterly)."""
        index = pd.date_range('2000-12-03 10:30', periods=474, freq='20H')
        seed = np.int64(201305122121).astype(np.uint32)
        np.random.seed(seed)
        x = 10 * np.random.rand(len(index))
        series = pd.Series(x, index=index)
        quarterly = wind.downsample(series, freq='Q')
        expected = pd.period_range(start='2000Q4', periods=6, freq='Q')
        self.assertListEqual(list(quarterly.index), list(expected))
        expected = [
            5.20769986209, 5.21883011776, 4.64734627795,
            4.76715486655, 5.2060181349, 0.348959422085
        ]
................................................................................
        self.assertTrue(np.allclose(result['B']['rec_rate'], [1, 1, 1, 0.333333]))
        self.assertTrue(np.allclose(result['possible'], [3, 3, 3, 3]))


class Test_downsample_dir(unittest.TestCase):
    def test_downsample_dir(self):
        index = pd.date_range('2000-01-01', freq='10T', periods=30, name='timestamp')
        d = pd.Series([
            206, 340, 265, 199, 107, 169, 286,  18, 143, 140, 288, 126,
            345, 336, 103, 132, 119, 282, 154, 223,  59, 174, 222, 351,
            145, 313, 101,  66, 135, 132
        ], index=index)
        s = pd.Series([
            8.46166109,  6.66049966,  2.28832706,  0.69091534,  8.86574959,
            8.40290133,  0.79775699,  8.50917337,  0.66806117,  5.00115906,
            9.37854938,  0.64840152,  7.0377572 ,  7.34612126,  9.78337364,
            2.2478703 ,  1.59568135,  6.08521493,  4.48504165,  7.61680989,
            2.37197815,  4.02293607,  9.84346178,  1.81458986,  0.23772917,
            6.95868632,  0.17872466,  3.77935404,  9.77546444,  9.89224031
        ], index=index)
................................................................................
class Test_monthly_means(unittest.TestCase):
    """Test function monthly_means."""
    def test_monthly_means(self):
        """Test function monthly_means."""
        index = pd.date_range('2000-01-01', periods=2000, freq='6H')
        x = np.arange(2000)
        y = np.sin(x/100) + 1
        df = pd.Series(y, index=index)
        df['2000-01-15 00:00': '2000-03-15 00:00'] = np.nan
        monthly = wind.monthly_means(df)

        self.assertEqual(len(monthly), 17)
        self.assertEqual(monthly.index.freq, 'M')

        expected = pd.PeriodIndex(