jldbc / pybaseball

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

Statcast example not running #246

Closed stephen1694 closed 2 years ago

stephen1694 commented 2 years ago

When I run the example statcast query provided, I get a lengthy list of errors.

This was my code: from pybaseball import statcast data = statcast(start_dt='2017-06-24', end_dt='2017-06-27'') data.head(2)

And below is the output:

This a large query, it may take a moment to complete 0%| | 0/4 [00:00<?, ?it/s] This is a large query, it may take a moment to complete This is a large query, it may take a moment to complete Traceback (most recent call last): File "", line 1, in File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main 0%| | 0/4 [00:00<?, ?it/s] Traceback (most recent call last): File "", line 1, in File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main exitcode = _main(fd, parent_sentinel) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main prepare(preparation_data) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path exitcode = _main(fd, parent_sentinel) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main prepare(preparation_data) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path 0%| | 0/4 [00:00<?, ?it/s] return _run_module_code(code, init_globals, run_name, This is a large query, it may take a moment to complete File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\sej16\PycharmProjects\pythonProject4\statcast.py", line 2, in return _run_module_code(code, init_globals, run_name, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code data = statcast(start_dt='2017-06-24', end_dt='2017-06-27') File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 110, in statcast _run_code(code, mod_globals, init_globals, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\sej16\PycharmProjects\pythonProject4\statcast.py", line 2, in data = statcast(start_dt='2017-06-24', end_dt='2017-06-27') File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 110, in statcast 0%| | 0/4 [00:00<?, ?it/s] Traceback (most recent call last): File "", line 1, in File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main exitcode = _main(fd, parent_sentinel) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main prepare(preparation_data) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path return _run_module_code(code, init_globals, run_name, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\sej16\PycharmProjects\pythonProject4\statcast.py", line 2, in data = statcast(start_dt='2017-06-24', end_dt='2017-06-27') File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 110, in statcast return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose,
return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose,return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose, File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in _handle_request

File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in _handle_request File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in _handle_request futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 697, in submit futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 697, in submit futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 697, in submit This is a large query, it may take a moment to complete 0%| | 0/4 [00:00<?, ?it/s] self._adjust_process_count() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 675, in _adjust_process_count self._adjust_process_count() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 675, in _adjust_process_count p.start() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start self._adjust_process_count() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 675, in _adjust_process_count p.start() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start p.start() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start 0%| | 0/4 [00:00<?, ?it/s] Traceback (most recent call last): File "", line 1, in File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main exitcode = _main(fd, parent_sentinel) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main prepare(preparation_data) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path return _run_module_code(code, init_globals, run_name, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\sej16\PycharmProjects\pythonProject4\statcast.py", line 2, in data = statcast(start_dt='2017-06-24', end_dt='2017-06-27') File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 110, in statcast return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose, File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in _handle_request futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 70, in futures = {executor.submit(_small_request, subq_start, subq_end, team=team) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 697, in submit self._adjust_process_count() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 675, in _adjust_process_count p.start() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start self._popen = self._Popen(self) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen self._popen = self._Popen(self) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen self._popen = self._Popen(self) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen self._popen = self._Popen(self) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen return Popen(process_obj) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in init return Popen(process_obj) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in init return Popen(process_obj) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in init return Popen(process_obj) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in init prep_data = spawn.get_preparation_data(process_obj._name) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data prep_data = spawn.get_preparation_data(process_obj._name)
prep_data = spawn.get_preparation_data(process_obj._name) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data _check_not_importing_main() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main _check_not_importing_main()_check_not_importing_main()

File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main raise RuntimeError(''' RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.
    raise RuntimeError('''raise RuntimeError('''

RuntimeErrorRuntimeError: : An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.
prep_data = spawn.get_preparation_data(process_obj._name)

File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data _check_not_importing_main() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main raise RuntimeError(''' RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

0%| | 0/4 [00:05<?, ?it/s] Traceback (most recent call last): File "C:\Users\sej16\PycharmProjects\pythonProject4\statcast.py", line 2, in data = statcast(start_dt='2017-06-24', end_dt='2017-06-27') File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 110, in statcast return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose, File "C:\Users\sej16\PycharmProjects\pythonProject4\venv\lib\site-packages\pybaseball\statcast.py", line 73, in _handle_request dataframe_list.append(future.result()) File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures_base.py", line 438, in result return self.get_result() File "C:\Users\sej16\AppData\Local\Programs\Python\Python39\lib\concurrent\futures_base.py", line 390, in get_result raise self._exception concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Process finished with exit code 1

tjburch commented 2 years ago

See #211.

tl;dr - wrap your call under a if __name__ == '__main__': to prevent Windows issues with multiprocessing, e.g.:

if __name__ == '__main__':
    stats = statcast()
tjburch commented 2 years ago

@stephen1694, were you able to make it run?

stephen1694 commented 2 years ago

Yes, thank you. I hadn't seen issue 211 and this solved the issue.

tjburch commented 2 years ago

Good to hear.

@schorrm, we can close this one.