jldbc / pybaseball

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

cache serializing error #438

Closed bdilday closed 2 months ago

bdilday commented 3 months ago

The cache writer has been writing corrupted files. The reason seems to be that statcast takes dates as args and these can't be json serialized, example,

>>> import json
>>> import datetime
>>> json.dumps(datetime.date.today())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable

closes https://github.com/jldbc/pybaseball/issues/437

ss77995ss commented 2 months ago

Hi @bdilday . It looks like this PR could also fix this issue! Could you also test this case, too? If so I am going to close my PR ref: https://github.com/jldbc/pybaseball/pull/379