Comments (6)
Interesting. I haven't encountered such an error after running multiple queries, though I did reduce the time span because it would take awhile. Could you post an image of what you run? Here's what I see on one such attempt:
from pybaseball.
I ran into this testing on a multiyear timespan statcast('2008-03-20','2011-11-11')
, but haven't seen it since. I'll see if it reproduces over the weekend.
From this it looks like it's caused by one or several rows having unexpected formatting (maybe a missing or extra delimiter), but I've since added some extra error handling that may have fixed this.
from pybaseball.
Closing this as I haven't run into the error or heard anybody else mention it in a while
from pybaseball.
I'm getting a similar error but only sometimes.
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 35, saw 4
Happens when I'm running statcast_single_game()
and sometimes when running statcast()
although the latter is less often. If I try re-running it, sometimes it works and sometimes it doesn't. I see the answer here which suggests adding error_bad_lines=False
to pd.read_csv()
.
I also see that this is referenced in /pybaseball/statcast.py on line 35 (and 43) but is commented out:
data = pd.read_csv(io.StringIO(s.decode('utf-8')))#, error_bad_lines=False) # skips 'bad lines' breaking scrapes. still testing this.
Is there any harm with me including error_bad_lines=False
, and why does it only error about half the time??
I'm a little worried that if I include the above 'fix' then I might occasionally be missing data that is sometimes there, and sometimes not.
from pybaseball.
Update to my above question. When I run it with error_bad_lines=False
I got this error as a result (when I try running it again it works... seems to fail roughly 30% of the time):
Traceback (most recent call last):
File "run.py", line 94, in <module>
method=method)
File "/home/jnederlo/mlb/pipeline/pipeline.py", line 21, in __init__
self.choose_process()
File "/home/jnederlo/mlb/pipeline/pipeline.py", line 31, in choose_process
self.scrape(day)
File "/home/jnederlo/mlb/pipeline/pipeline.py", line 51, in scrape
parser = Parser({'templateName': 'statcast_game'}, day, self.db, self.statcast_game_ids)
File "/home/jnederlo/mlb/parser/parser.py", line 40, in __init__
self.sources[self.data['templateName']]()
File "/home/jnederlo/mlb/parser/parser.py", line 353, in statcast_game
df = statcast_single_game(mlb_game_pk)
File "/home/jnederlo/.local/share/virtualenvs/mlb-58UnosLS/lib/python3.6/site-packages/pybaseball/statcast.py", line 215, in statcast_single_game
data = postprocessing(data, team)
File "/home/jnederlo/.local/share/virtualenvs/mlb-58UnosLS/lib/python3.6/site-packages/pybaseball/statcast.py", line 155, in postprocessing
data[numeric_cols] = data[numeric_cols].astype(float)
File "/home/jnederlo/.local/share/virtualenvs/mlb-58UnosLS/lib/python3.6/site-packages/pandas/core/frame.py", line 2133, in __getitem__
return self._getitem_array(key)
File "/home/jnederlo/.local/share/virtualenvs/mlb-58UnosLS/lib/python3.6/site-packages/pandas/core/frame.py", line 2177, in _getitem_array
indexer = self.loc._convert_to_indexer(key, axis=1)
File "/home/jnederlo/.local/share/virtualenvs/mlb-58UnosLS/lib/python3.6/site-packages/pandas/core/indexing.py", line 1269, in _convert_to_indexer
.format(mask=objarr[mask]))
KeyError: "['release_speed' 'release_pos_x' 'release_pos_z' 'batter' 'pitcher' 'zone'\n 'hit_location' 'balls' 'strikes' 'game_year' 'pfx_x' 'pfx_z' 'plate_x'\n 'plate_z' 'on_3b' 'on_2b' 'on_1b' 'outs_when_up' 'inning' 'hc_x' 'hc_y'\n 'fielder_2' 'vx0' 'vy0' 'vz0' 'ax' 'ay' 'az' 'sz_top' 'sz_bot'\n 'hit_distance_sc' 'launch_speed' 'launch_angle' 'effective_speed'\n 'release_spin_rate' 'release_extension' 'game_pk' 'pitcher.1'\n 'fielder_2.1' 'fielder_3' 'fielder_4' 'fielder_5' 'fielder_6' 'fielder_7'\n 'fielder_8' 'fielder_9' 'release_pos_y' 'estimated_ba_using_speedangle'\n 'estimated_woba_using_speedangle' 'woba_value' 'woba_denom' 'babip_value'\n 'iso_value' 'launch_speed_angle' 'at_bat_number' 'pitch_number'\n 'home_score' 'away_score' 'bat_score' 'fld_score' 'post_away_score'\n 'post_home_score' 'post_bat_score' 'post_fld_score'] not in index"```
from pybaseball.
I'm also getting this error from the statcast_batter() function, again not reliably. Running a for loop with about rows. First time it was raised at row 592. Second time it was raised at 925. I'm thinking I'll just define a custom function with exception handling and go back to the rows that get skipped. Just wanted you to know it's still happening.
from pybaseball.
Related Issues (20)
- Fangraphs per-Team leaderboard splits
- 'max_results' parameter for fangraphs query not respected when 'month' parameter given HOT 2
- get_splits() throwing unexpected error
- batting_stats() and pitching_stats() errors out for certain players/years HOT 1
- Cannot fetch FanGraphs stats using batting_stats and pitching_stats anymore, code used to work now just gets stuck loading forever
- Getting pitcher "exit" information?
- Range functions update time
- Splits HOT 1
- statcast throwing KeyError on certain dates in 2023 HOT 3
- Fangraphs functions fail to scrape data, returns empty DF after site update HOT 1
- team_pitching returning blank frame with only teamIDfg column HOT 1
- How to store schedule and scores
- Can't seem to get pitching/batting stats. HOT 19
- statcast_pitcher_pitch_movement & statcast_pitcher_active_spin not importing HOT 1
- Retrieving SB data HOT 2
- Fangraphs add league="mnl" data not working HOT 1
- Statcast_Pitcher only working for selective players in 2017 season HOT 2
- Refactor Print statements to use python logging module
- Failing Test
- first pitch result data HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pybaseball.