mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 01:14:26 +08:00
BUG: DataPanelSource was looping in the incorrect order.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
import pandas as pd
|
||||
import pytz
|
||||
from itertools import cycle
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -59,16 +60,16 @@ class TestDataFrameSource(TestCase):
|
||||
start = pd.datetime(1993, 1, 1, 0, 0, 0, 0, pytz.utc)
|
||||
end = pd.datetime(2002, 1, 1, 0, 0, 0, 0, pytz.utc)
|
||||
data = factory.load_bars_from_yahoo(stocks=stocks,
|
||||
indexes={},
|
||||
start=start,
|
||||
end=end)
|
||||
|
||||
check_fields = ['sid', 'open', 'high', 'low', 'close',
|
||||
'volume', 'price']
|
||||
source = DataPanelSource(data)
|
||||
stocks_iter = cycle(stocks)
|
||||
for event in source:
|
||||
self.assertTrue('sid' in event)
|
||||
self.assertTrue('open' in event)
|
||||
self.assertTrue('high' in event)
|
||||
self.assertTrue('low' in event)
|
||||
self.assertTrue('close' in event)
|
||||
self.assertTrue('volume' in event)
|
||||
self.assertTrue('price' in event)
|
||||
for check_field in check_fields:
|
||||
self.assertIn(check_field, event)
|
||||
self.assertTrue(isinstance(event['volume'], (int, long)))
|
||||
self.assertEqual(stocks_iter.next(), event['sid'])
|
||||
|
||||
@@ -134,8 +134,9 @@ class DataPanelSource(DataSource):
|
||||
return self.arg_string
|
||||
|
||||
def raw_data_gen(self):
|
||||
for sid, dataframe in self.data.iteritems():
|
||||
for dt, series in dataframe.iterrows():
|
||||
for dt in self.data.major_axis:
|
||||
df = self.data.major_xs(dt)
|
||||
for sid, series in df.iterkv():
|
||||
if sid in self.sids:
|
||||
event = {
|
||||
'dt': dt,
|
||||
|
||||
Reference in New Issue
Block a user