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

NBA: adding TypeError checks around operations #394

Merged
merged 3 commits into from
Apr 19, 2020

Conversation

SeanAmmirati
Copy link
Contributor

This small PR simply adds some exception handling to some of the calculations for the NBA boxscore classes.

I also intend to do this for the other classes as well.

This was done because in the current state, running something like the following would raise a TypeError:

from sportsreference.nba.boxscore import Boxscore

bs = Boxscore('194910290TRI')
df = bs.dataframe

This was because the information that would have been required for all of these operations were valued None. While the decorators handle this issue for the particular values, the TypeError would happen with the arithmetic operators.

This assumes that the attributes will only be of the correct type (float or int) or NoneType.

This should also be done for the other classes. It appears that this will be a problem for very old games. For reference, this was the first NBA basketball game available on basketball reference.

Happy to discuss this further or perhaps consider other ways to handle this. Also will be happy to do this for the other classes as I get to them.

@SeanAmmirati SeanAmmirati changed the title adding TypeError checks around operations NBA: adding TypeError checks around operations Apr 12, 2020
@roclark roclark self-requested a review April 12, 2020 19:42
@roclark roclark added the bug Something isn't working label Apr 12, 2020
@roclark roclark added this to the Release 0.6.0 milestone Apr 12, 2020
Copy link
Owner

@roclark roclark left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @SeanAmmirati, this is very nicely done (side note, I love the profile picture)! I think this is a wonderful update and it's always nice to cleanly handle errors.

I think the code looks great, and am happy to merge, but if you don't mind, I think it would be good to include some test cases which will run into these situations just to verify in the testing suite that they are functioning as expected. This could probably sit in the test_nba_boxscore unit tests at the end. Let me know if you have any questions and I will be happy to help out.

On a related note, the action used to upload coverage reports to Codecov is currently broken for updates from forked repositories, but I have a PR (#397) which should resolve this issue. I will merge that once its tests complete so hopefully coverage reports on future updates (like this) are able to be displayed properly, and all actions can complete as expected.

Lastly, I would be very happy to accept similar PRs for other sports too if you desire down the road! I'm always happy to work with the community to make this package more robust!

Thanks again for this wonderful update!

Comment on lines +989 to +996
try:
result = float(self.away_two_point_field_goals) / \
float(self.away_two_point_field_goal_attempts)
except TypeError:
result = None
else:
result = round(float(result), 3)
return result
Copy link
Owner

Choose a reason for hiding this comment

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

Beautiful! 😃

@SeanAmmirati
Copy link
Contributor Author

Hi @roclark, thanks for the quick response!

Happy to help in any way I can. Thanks for creating this package -- it is incredibly useful and helpful.

More than happy to add the test cases, will do that shortly and check back once this has been done. Also apologies, I force pushed another small edit to avoid creating another commit, just fyi in case there are any conflicts in the history.

Thanks!

@SeanAmmirati
Copy link
Contributor Author

Just added some unit tests.

Please let me know if this formatting works or if you have any suggestions.

Also, thanks for the note on the profile picture, GLaDOS! The cake is a lie! 👍

Thanks!

Sean

@codecov
Copy link

codecov bot commented Apr 19, 2020

Codecov Report

Merging #394 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #394   +/-   ##
=======================================
  Coverage   99.97%   99.97%           
=======================================
  Files          48       48           
  Lines       10590    10616   +26     
=======================================
+ Hits        10587    10613   +26     
  Misses          3        3           
Impacted Files Coverage Δ
sportsreference/nba/boxscore.py 100.00% <100.00%> (ø)
sportsreference/nba/roster.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15e70fb...ef89497. Read the comment docs.

@roclark
Copy link
Owner

roclark commented Apr 19, 2020

Hey @SeanAmmirati, sorry for not getting back to you earlier - it's been a very long week. These updates look great, and I appreciate the work on the test cases! Also, I'm happy to see the the codecov reports are now working on forked updates. This PR looks in great shape to me, so I will go ahead and merge it with master.

Thank you again both for the update and for your patience! This is absolutely wonderful!

@roclark roclark merged commit 9fcd076 into roclark:master Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants