Jensen-holm commited on
Commit
4a9bb01
·
verified ·
1 Parent(s): 633fc02

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -7
README.md CHANGED
@@ -22,23 +22,43 @@ This data is available through the pybaseball pacakge and the baseballr package,
22
  pip install git+https://github.com/Jensen-holm/statcast-era-pitches.git
23
  ```
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ```python
26
  import statcast_pitches
27
 
28
  # get bat tracking data from 2024
 
29
  query_2024_bat_speed = f"""
30
  SELECT bat_speed, swing_length
31
  FROM pitches
32
  WHERE
33
- YEAR(game_date) = '2024'
34
  AND bat_speed IS NOT NULL;
35
  """
36
 
37
  if __name__ == "__main__":
38
  bat_speed_24_df = statcast_pitches.load(
39
- query=query_2024_bat_speed,
40
- pandas=True, # default is polars
41
- )
42
 
43
  print(bat_speed_24_df.head(3))
44
  ```
@@ -53,6 +73,8 @@ output:
53
  **Notes**:
54
  - If no query is specified, all data from 2015-present will be loaded into a DataFrame.
55
  - The table in your query MUST be called 'pitches', or it will fail.
 
 
56
 
57
  ### With HuggingFace API
58
 
@@ -98,13 +120,18 @@ statcast_pitches <- read_parquet(
98
 
99
  see the [dataset](https://huggingface.co/datasets/Jensen-holm/statcast-era-pitches) on HugingFace itself for more details.
100
 
101
- ## Benchmarking
102
 
103
  ![dataset_load_times](dataset_load_times.png)
104
 
105
- | Load Time (s) | API |
106
  |---------------|-----|
107
  | 1421.103 | pybaseball |
108
  | 26.899 | polars |
109
  | 33.093 | pandas |
110
- | 68.692 | duckdb |
 
 
 
 
 
 
22
  pip install git+https://github.com/Jensen-holm/statcast-era-pitches.git
23
  ```
24
 
25
+ **Example 1 w/ polars (suggested)**
26
+ ```python
27
+ import statcast_pitches
28
+ import polars as pl
29
+
30
+ # load all pitches from 2015-present
31
+ pitches_lf = statcast_pitches.load()
32
+
33
+ # filter to get 2024 bat speed data
34
+ bat_speed_24_df = (pitches_lf
35
+ .filter(pl.col("game_date").dt.year() == 2024)
36
+ .select("bat_speed", "swing_length")
37
+ .collect())
38
+ ```
39
+
40
+ **Notes**
41
+ - Because `statcast_pitches.load()` uses a LazyFrame, we can load it much faster and even perform operations on it before 'collecting' it into memory. If it were loaded as a DataFrame, this code would execute in ~30-60 seconds, instead it runs between 2-8 seconds.
42
+
43
+ **Example 2 Duckdb**
44
  ```python
45
  import statcast_pitches
46
 
47
  # get bat tracking data from 2024
48
+ params = ("2024",)
49
  query_2024_bat_speed = f"""
50
  SELECT bat_speed, swing_length
51
  FROM pitches
52
  WHERE
53
+ YEAR(game_date) =?
54
  AND bat_speed IS NOT NULL;
55
  """
56
 
57
  if __name__ == "__main__":
58
  bat_speed_24_df = statcast_pitches.load(
59
+ query=query_2024_bat_speed,
60
+ params=params,
61
+ ).collect()
62
 
63
  print(bat_speed_24_df.head(3))
64
  ```
 
73
  **Notes**:
74
  - If no query is specified, all data from 2015-present will be loaded into a DataFrame.
75
  - The table in your query MUST be called 'pitches', or it will fail.
76
+ - Since `load()` returns a LazyFrame, notice that I had to call `pl.DataFrame.collect()` before calling `head()`
77
+ - This is slower than the other polars approach, however sometimes using SQL is fun
78
 
79
  ### With HuggingFace API
80
 
 
120
 
121
  see the [dataset](https://huggingface.co/datasets/Jensen-holm/statcast-era-pitches) on HugingFace itself for more details.
122
 
123
+ ## Eager Benchmarking
124
 
125
  ![dataset_load_times](dataset_load_times.png)
126
 
127
+ | Eager Load Time (s) | API |
128
  |---------------|-----|
129
  | 1421.103 | pybaseball |
130
  | 26.899 | polars |
131
  | 33.093 | pandas |
132
+ | 68.692 | duckdb |
133
+
134
+ ```
135
+
136
+
137
+