Skip to content
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

Merged

Conversation

shadiakiki1986
Copy link
Contributor

otherwise, the index could come out as a float because of the division ahead of it

@coveralls
Copy link

coveralls commented Feb 13, 2017

Coverage Status

Coverage increased (+0.0009%) to 87.412% when pulling eb748c7 on shadiakiki1986:bugfix_index_should_be_int into 296307a on quantopian:master.

@freddiev4
Copy link
Contributor

freddiev4 commented Mar 6, 2017

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

@shadiakiki1986
Copy link
Contributor Author

Hello. I'm wrapping zipline's blotter class in a django application here. I ran into this issue by pure coincidence. The division yielded a float. I'm not sure where exactly in my code it was triggered, but it might be here


# cast to int for pandas
# https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/base.py#L247
num_days = int(num_days)
Copy link
Contributor

@freddiev4 freddiev4 Mar 7, 2017

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

Copy link
Contributor Author

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

@@ -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
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shortened the lines

@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage increased (+0.001%) to 87.413% when pulling e29aeb3 on shadiakiki1986:bugfix_index_should_be_int into 296307a on quantopian:master.

@@ -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
Copy link
Contributor

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)

Copy link
Contributor

@freddiev4 freddiev4 Mar 8, 2017

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)

Copy link
Contributor Author

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

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage remained the same at 87.474% when pulling 5bea92f on shadiakiki1986:bugfix_index_should_be_int into 40aec72 on quantopian:master.

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage remained the same at 87.474% when pulling 5bea92f on shadiakiki1986:bugfix_index_should_be_int into 40aec72 on quantopian:master.

@shadiakiki1986
Copy link
Contributor Author

shadiakiki1986 commented Mar 16, 2017

Btw, here is my travis build which demonstrates this issue

@freddiev4
Copy link
Contributor

Looks good to merge 👍 thanks for the PR

@freddiev4 freddiev4 merged commit 5fd20e1 into quantopian:master Mar 16, 2017
@shadiakiki1986 shadiakiki1986 deleted the bugfix_index_should_be_int branch March 17, 2017 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants