New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: convert index to int so that the pandas indexing doesnt fail #1683
bugfix: convert index to int so that the pandas indexing doesnt fail #1683
Conversation
Hi @shadiakiki1986 thanks for the PR. I was wondering if you could explain/show some test where this is an issue, so I could try and reproduce it, or how you caught this |
zipline/data/minute_bars.py
Outdated
|
||
# cast to int for pandas | ||
# https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/base.py#L247 | ||
num_days = int(num_days) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if we're going to check for an int, we should be doing this earlier, before we even check for num_days == 0
We can do that on line 552; using the //
operator which does integer division in both Python 2 and 3: num_days = data['shape'][0] // self._minutes_per_day
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a better idea. I just pushed a new commit amending the PR
zipline/data/minute_bars.py
Outdated
@@ -549,7 +549,9 @@ def last_date_in_output_for_sid(self, sid): | |||
with open(sizes_path, mode='r') as f: | |||
sizes = f.read() | |||
data = json.loads(sizes) | |||
num_days = data['shape'][0] / self._minutes_per_day | |||
# use integer division so that the result is an int for pandas index later | |||
# https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/base.py#L247 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the flake8 tests failed because line 552 is too long (and probably 553 as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shortened the lines
zipline/data/minute_bars.py
Outdated
@@ -549,7 +549,9 @@ def last_date_in_output_for_sid(self, sid): | |||
with open(sizes_path, mode='r') as f: | |||
sizes = f.read() | |||
data = json.loads(sizes) | |||
num_days = data['shape'][0] / self._minutes_per_day | |||
# use integer division so that the result is an int | |||
# for pandas index later https://goo.gl/VAW649 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok great. Just one last thing; we should keep this link expanded (so people know it's a safe link to click). You can make the flake8 tests ignore the length of this line by adding # noqa
line 553. So it would look like:
# for pandas index later <link> # noqa
Should've mentioned that before, sorry! (after that it should be good to merge)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you should squash your commits into 1, and change the commit message to say BUG: <description>
(to be consistent with our dev guidelines https://github.com/quantopian/zipline/wiki/Zipline-development-guidelines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem :) Done and rebased
e29aeb3
to
045d95f
Compare
045d95f
to
5bea92f
Compare
Btw, here is my travis build which demonstrates this issue |
Looks good to merge 👍 thanks for the PR |
otherwise, the index could come out as a float because of the division ahead of it