jldbc / pybaseball

Pull current and historical baseball statistics using Python (Statcast, Baseball Reference, FanGraphs)
MIT License
1.18k stars 322 forks source link

Can't seem to get pitching/batting stats. #381

Closed shortenedname closed 10 months ago

shortenedname commented 10 months ago

I was following a tutorial grabbing batting and pitching stats and my Pandas Dataframe was only returning an Empty Dataframe with the only column being "IDfg". I then went to the repo and copy pasted the batting_stats() and pitching_stats() code examples and am still getting the same thing. Statcast function works for me though, would like to see if I'm doing something wrong

`` pybaseball

shortenedname commented 10 months ago

Wanted to come back and add/report that importing and using batting_stats_range() and pitching_stats_range() functions seems to work, so I'm assuming it's got something to do w/ fangraphs changing some stuff like another person pointed out in a different issue and the updates need to be reflected.

ss77995ss commented 10 months ago

I think it is the same issue with #376 The fix PR is merged to the main branch but not release to PyPI.

Therefore, if you want to have the fix version you might try to uninstall pybaseball and install the main branch's code.

- pip install pybaseball
# if the package has already been installed
+ pip uninstall pybaseball
+ pip install git+https://github.com/jldbc/pybaseball.git@master
stephenlacey531 commented 10 months ago

Works for me thx !

shortenedname commented 10 months ago

I'm still getting empty columns but the other functions are working still. First I uninstalled pybaseball from command prompt and then anaconda shell to be sure. Then I copy/pasted your suggested line edit into my notebook file in VS, and when that didn't work I did it from my Anaconda shell. Then I restarted everything, still empty columns. @ss77995ss

Is there something I'm missing still? pybaseball from master pybaseball from masteter2

ss77995ss commented 10 months ago

Hi @shortenedname Have you tried to uninstall pybaseball first? If you not uninstall the old version. It may still use the old code. I forgot to add the uninstall line in my previous comment.

pip uninstall pybaseball
pip install git+https://github.com/jldbc/pybaseball.git@master
tcamino24 commented 10 months ago

Hey @ss77995ss currently having these same issues in JupyterLab environment. The kernel will not finish when i try and run pip uninstall pybaseball or when i try and call on the newly imported package provided above in this thread

shortenedname commented 10 months ago

Thanks for the suggestion @ss77995ss, because I hadn't thought of that either. I found copy/pasting the lines as is will lead to a inf. loop and a kernel crash like @tcamino24 is experiencing. I tried using %pip install git+https://github.com/jldbc/pybaseball.git@master and that also has given empty dataframes when importing batting_stats and pitching_stats :/

ss77995ss commented 10 months ago

@shortenedname @tcamino24 Do you have these message showing on your kernel? If so try to type Y and submit to confirm the target. Then it will process the uninstall process.

pip uninstall pybaseball

Found existing installation: pybaseball 2.2.5
Uninstalling pybaseball-2.2.5:
  Would remove:
    /usr/local/lib/python3.10/dist-packages/pybaseball-2.2.5.dist-info/*
    /usr/local/lib/python3.10/dist-packages/pybaseball/*
Proceed (Y/n)?
tcamino24 commented 10 months ago

@ss77995ss where should i be running that code? in jupyterlabs it just creates an infinite loop and in my command prompt it says pip is not recognized

stephenlacey531 commented 10 months ago

Also, you might need to restart your notebook / kernel following the install of %pip install git+https://github.com/jldbc/pybaseball.git@master

shortenedname commented 10 months ago

@stephenlacey531 @ss77995ss thank you both for being lovely and helping me out. I got in the terminal of jupyterlabs and uninstalled, then ran the %pip install git+https://github.com/jldbc/pybaseball.git@master in an actual notebook in Jupyter and not my add-on in VSCode, restarted the kernel and it worked on both Jupyter and in VSCode. 👍

I kind of want to close the issue, but I'll wait for @tcamino24 to read my update and see if what I did works for them

ss77995ss commented 10 months ago

@tcamino24 try !pip uninstall -y pybaseball. This command will bypass the confirmation and the infinite loop should disappear

tcamino24 commented 10 months ago

that worked for the uninstall thank you! when im going to call on the package in jupyterlabs, what should i try and import now? LIke before it was import pybaseball and then from pybaseball import batting_stats. What should replace pybaseball now in the code, something like git+https://github.com/jldbc/pybaseball.git@master ?

ss77995ss commented 10 months ago

@shortenedname I'm glad to help! It is weird we can type to confirm in Colab but not in VScode's jupyter notebook

@tcamino24 you can still import pybaseball after installing git+https://github.com/jldbc/pybaseball.git@master They both pybaseball the different is that one is from PyPI and another is from the main branch Have a try!

tcamino24 commented 10 months ago

worked flawlessly! thanks so much for the help, thought the FanGraphs update was gonna completely derail the rest of the season. I really appreciate it, take care!

bclark08 commented 10 months ago

I am still getting the blank IDfg table. I did the full uninstall and reinstalled using git. I then checked /pybaseball/datasources/fangraphs.py and confirmed that line 14 reads:

_FG_LEADERS_URL = "/leaders-legacy.aspx"

I've restarted the jupyter notebook from which I do my weekly stats and am still getting the blank table. Anyone experiencing this or know how to fix?

ss77995ss commented 10 months ago

Hi @bclark08 could you maybe provide some of your code? I'll try to reproduce the issue and find what cause the problem

bclark08 commented 10 months ago

@ss77995ss thank you for responding!

I am at work right now and don't have access to my code, but I will try to remember to give you a code snippet later tonight. I think it is actually an issue with Jupyter Notebook, as I have had similar issues with other packages in the past.

On the upside, I was rather frustrated and merged all of my code into a single, locally-saved script and ran it from the command line. This worked flawlessly, which further heightens my suspicion that there is an issue with Jupyter Notebook--I am guessing having something to do with where or how I initially installed and saved it.

ss77995ss commented 10 months ago

@bclark08 No hurry!

BTW, Could you open another issue once you get your code? Since this one is closed. We could discuss in the newest issue.