Skip to content

Commit f148f59

Browse files
committed
Add OptionalFloat to ExpectedStatistics & update docs in hitting & README.md
1 parent a14637e commit f148f59

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Or access individual fields directly
437437
... print(f"Batting Avg: {split.stat.avg}")
438438
Games: 140
439439
Home Runs: 20
440-
Batting Avg: .274
440+
Batting Avg: 0.274
441441
```
442442

443443
### Team Stats
@@ -486,8 +486,8 @@ Print stats as JSON
486486
>>> for split in expected.splits:
487487
... print(f"Expected AVG: {split.stat.avg}")
488488
... print(f"Expected SLG: {split.stat.slg}")
489-
Expected AVG: .259
490-
Expected SLG: .394
489+
Expected AVG: 0.259
490+
Expected SLG: 0.394
491491
```
492492

493493
### vsPlayer Stats
@@ -528,8 +528,8 @@ Games: 2, Hits: 2
528528
... for zone in split.stat.zones:
529529
... print(f" Zone {zone.zone}: {zone.value}")
530530
Stat: battingAverage
531-
Zone 01: .226
532-
Zone 02: .400
531+
Zone 01: 0.226
532+
Zone 02: 0.400
533533
...
534534
```
535535

‎mlbstatsapi/models/stats/hitting.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AdvancedHittingSplit(MLBBaseModel):
2626
The amount of sac bunts.
2727
sac_flies : int
2828
The amount of sac flies.
29-
babip : str
29+
babip : float
3030
Batting Average on Balls in Play.
3131
extra_base_hits : int
3232
The amount of extra base hits.
@@ -38,17 +38,17 @@ class AdvancedHittingSplit(MLBBaseModel):
3838
The amount of GIDP opportunities.
3939
number_of_pitches : int
4040
The number of pitches the batter has faced.
41-
pitches_per_plate_appearance : str
41+
pitches_per_plate_appearance : float
4242
The avg amount of pitches per plate appearance.
43-
walks_per_plate_appearance : str
43+
walks_per_plate_appearance : float
4444
The avg walks per plate appearance.
45-
strikeouts_per_plate_appearance : str
45+
strikeouts_per_plate_appearance : float
4646
The amount of strike outs per plate appearance.
47-
home_runs_per_plate_appearance : str
47+
home_runs_per_plate_appearance : float
4848
The amount of home runs per plate appearance.
49-
walks_per_strikeout : str
49+
walks_per_strikeout : float
5050
The amount of walks per strike out.
51-
iso : str
51+
iso : float
5252
Isolated power.
5353
reached_on_error : int
5454
The amount of times the batter has reached base on an error.
@@ -144,19 +144,19 @@ class SimpleHittingSplit(MLBBaseModel):
144144
The number of hits for the batter.
145145
hit_by_pitch : int
146146
The number of pitches the batter has been hit by.
147-
avg : str
147+
avg : float
148148
The batting avg of the batter.
149149
at_bats : int
150150
The number of at bats of the batter.
151-
obp : str
151+
obp : float
152152
The on base percentage of the batter.
153-
slg : str
153+
slg : float
154154
The slugging percentage of the batter.
155-
ops : str
155+
ops : float
156156
The on-base plus slugging of the batter.
157157
caught_stealing : int
158158
The amount of times the batter has been caught stealing.
159-
caught_stealing_percentage : str
159+
caught_stealing_percentage : float
160160
The caught stealing percentage.
161161
stolen_bases : int
162162
The amount of stolen bases achieved by the batter.
@@ -180,7 +180,7 @@ class SimpleHittingSplit(MLBBaseModel):
180180
The number of sac bunts performed by the batter.
181181
sac_flies : int
182182
The number of sac flies performed by the batter.
183-
babip : str
183+
babip : float
184184
The batting average of balls in play of the batter.
185185
groundouts_to_airouts : int
186186
The groundout-to-airout ratio of the batter.

‎mlbstatsapi/models/stats/stats.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional, List, Any, ClassVar
22
from pydantic import Field, field_validator
3-
from mlbstatsapi.models.base import MLBBaseModel
3+
from mlbstatsapi.models.base import MLBBaseModel, OptionalFloat
44
from mlbstatsapi.models.teams import Team
55
from mlbstatsapi.models.people import Person, Batter, Position
66
from mlbstatsapi.models.sports import Sport
@@ -47,10 +47,10 @@ class ExpectedStatistics(MLBBaseModel):
4747
wobacon : str
4848
Expected wOBA on contact.
4949
"""
50-
avg: str
51-
slg: str
52-
woba: str
53-
wobacon: str = Field(alias="wobaCon")
50+
avg: OptionalFloat
51+
slg: OptionalFloat
52+
woba: OptionalFloat
53+
wobacon: OptionalFloat = Field(alias="wobaCon")
5454

5555

5656
class Sabermetrics(MLBBaseModel):
@@ -239,7 +239,7 @@ class HotColdZones(Split):
239239
stat : Zones
240240
The hot cold zones for the stat.
241241
"""
242-
_stat: ClassVar[List[str]] = ['hotColdZones']
242+
_stat: ClassVar[List[OptionalFloat]] = ['hotColdZones']
243243
stat: Zones
244244

245245

0 commit comments

Comments
 (0)