gs-quant
gs-quant copied to clipboard
[BUG] Dataset date handling is broken with dataclasses-json version 0.6.5 dependency, gives ValueError: Cannot convert 2024-04-29 to date
Describe the bug Dataset date handling is broken
This problem is caused by the change in the dataclasses-json, since version 0.6.5 of the library.
That library is a dependency of gs-quant that was changed here:
https://github.com/lidatong/dataclasses-json/releases/tag/v0.6.5
The breaking change was introduced on 29th of April 2024 by the library dependency.
To Reproduce Steps to reproduce the behavior with code example:
from gs_quant.data import Dataset
import datetime as dt
ds = Dataset('EDRVOL_PERCENT_PREMIUM')
date = dt.datetime.strptime('2024-04-29', '%Y-%m-%d').date()
assetId = 'MA4B66MW5E27U8P32SB'
ds.get_data(start=date, end=date, assetId=assetId)
Gives an error:
Traceback (most recent call last):
File "C:\Code\GS\date_issue.py", line 6, in <module>
ds.get_data(start=date, end=date, assetId=assetId)
File "C:\Code\GS\.venv\Lib\site-packages\gs_quant\data\dataset.py", line 156, in get_data
query = self.provider.build_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Code\GS\.venv\Lib\site-packages\gs_quant\api\data.py", line 88, in build_query
query = DataQuery(
^^^^^^^^^^
File "C:\Code\GS\.venv\Lib\site-packages\gs_quant\base.py", line 86, in wrapper
return init(self, *args, **normalised_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 8, in __init__
File "C:\Code\GS\.venv\Lib\site-packages\gs_quant\base.py", line 231, in __setattr__
value = self.__coerce_value(fld.type, value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Code\GS\.venv\Lib\site-packages\gs_quant\base.py", line 252, in __coerce_value
return _decode_generic(typ, value, False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Code\GS\.venv\Lib\site-packages\dataclasses_json\core.py", line 323, in _decode_generic
res = _decode_type(type_arg, value, infer_missing)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Code\GS\.venv\Lib\site-packages\dataclasses_json\core.py", line 233, in _decode_type
return _get_decoder_in_global_config(type_)(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Code\GS\.venv\Lib\site-packages\gs_quant\json_convertors.py", line 39, in decode_optional_date
raise ValueError(f'Cannot convert {value} to date')
ValueError: Cannot convert 2024-04-29 to date
Expected behavior
The code should not throw a ValueError
Screenshots Not applicable
Systems setup:
- OS: Windows 10
- Python version: 3.11.6
- GS-Quant version 1.0.72
Additional context
The workaround for the issue is to pin dataclasses-json to version 0.6.4
This affects versions prior to 1.0.72 as well. Based on https://github.com/goldmansachs/gs-quant/commit/b6f16ada98c525b1d5c285485dc891175053240b I'm assuming we'll need to bump to 1.0.74?
Yes, it looks that prior versions are also affected, I've ran in to the same issue with 1.0.66.
The setup.py change in 1.0.74 applies the workaround I mentioned, so that resolves this issue