gs-quant icon indicating copy to clipboard operation
gs-quant copied to clipboard

[BUG] `Dataset.get_data` fails with string `start_time`/`end_time`

Open theavey opened this issue 2 years ago • 0 comments

Describe the bug Dataset.get_data fails with string start_time/end_time

To Reproduce

from gs_quant.data import Dataset

ds = Dataset("EDRVS_EXPIRY_INTRADAY_PREMIUM")

ds.get_data(
    assetId=[
        "MA067JXW39B5T8VS",
        "MA07M4WC9PY2FBFG",
        "MA09RV3TD3ZEAZY3",
        "MA0B74FZFBAMZMQP",
        "MA0CT27ED3K3JD04",
    ],
    start_time="2022-03-03T00:00:00+00:00",
    end_time="2022-03-03T23:59:59+00:00",
    limit=10_000,
    strikeReference=["spot", "forward", "normalized", "delta"],
)

Expected behavior get back a dataframe of data with no exceptions

Screenshots Seems unneeded

Systems setup:

  • OS: Windows 10
  • Python version: '3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:22:46) [MSC v.1916 64 bit (AMD64)]'
  • GS-Quant version: '0.9.9'

Additional context below is the stack trace. Didn't dig into your code fully, but seems to expect a timestamp, not a string, though does work if I pass in pd.Timestamps:

ds.get_data(
    assetId=[
        "MA067JXW39B5T8VS",
        "MA07M4WC9PY2FBFG",
        "MA09RV3TD3ZEAZY3",
        "MA0B74FZFBAMZMQP",
        "MA0CT27ED3K3JD04",
    ],
    start_time=pd.Timestamp("2022-03-03T00:00:00+00:00"),
    end_time=pd.Timestamp("2022-03-03T23:59:59+00:00"),
    limit=10_000,
    strikeReference=["spot", "forward", "normalized", "delta"],
)

TypeError Traceback (most recent call last) Input In [7], in <cell line: 1>() ----> 1 ds.get_data( 2 assetId=[ 3 "MA067JXW39B5T8VS", 4 "MA07M4WC9PY2FBFG", 5 "MA09RV3TD3ZEAZY3", 6 "MA0B74FZFBAMZMQP", 7 "MA0CT27ED3K3JD04", 8 ], 9 start_time="2022-03-03T00:00:00+00:00", 10 end_time="2022-03-03T23:59:59+00:00", 11 limit=10_000, 12 strikeReference=["spot", "forward", "normalized", "delta"], 13 )

File C:\ProgramData\Miniconda3\envs\t_env\lib\site-packages\gs_quant\data\dataset.py:122, in Dataset.get_data(self, start, end, as_of, since, fields, asset_id_type, **kwargs) 100 """ 101 Get data for the given range and parameters 102 (...) 117 >>> weather_data = weather.get_data(dt.date(2016, 1, 15), dt.date(2016, 1, 16), city=('Boston', 'Austin')) 118 """ 120 field_names = None if fields is None else list(map(lambda f: f if isinstance(f, str) else f.value, fields)) --> 122 query = self.provider.build_query( 123 start=start, 124 end=end, 125 as_of=as_of, 126 since=since, 127 fields=field_names, 128 **kwargs 129 ) 130 data = self.provider.query_data(query, self.id, asset_id_type=asset_id_type) 132 return self.provider.construct_dataframe_with_types(self.id, data)

File C:\ProgramData\Miniconda3\envs\t_env\lib\site-packages\gs_quant\api\data.py:101, in DataApi.build_query(start, end, as_of, since, restrict_fields, format, dates, **kwargs) 99 snake_case_field = inflection.underscore(field) 100 if snake_case_field in query_properties: --> 101 setattr(query, snake_case_field, value) 102 else: 103 query.where[field] = value

File C:\ProgramData\Miniconda3\envs\t_env\lib\site-packages\gs_quant\base.py:226, in Base.setattr(self, key, value) 223 raise ValueError(f'{key} cannot be set') 225 key = snake_case_key --> 226 value = self.__coerce_value(fld.type, value) 227 self._property_changed(key, value) 228 elif key == 'name':

File C:\ProgramData\Miniconda3\envs\t_env\lib\site-packages\gs_quant\base.py:253, in Base.__coerce_value(cls, typ, value) 251 return value.to_dict() 252 if _is_supported_generic(typ): --> 253 return _decode_generic(typ, value, False) 254 else: 255 return value

File C:\ProgramData\Miniconda3\envs\t_env\lib\site-packages\dataclasses_json\core.py:277, in decode_generic(type, value, infer_missing) 275 res = _decode_generic(type_arg, value, infer_missing) 276 else: --> 277 res = _support_extended_types(type_arg, value) 278 else: # Union (already decoded or unsupported 'from_json' used) 279 res = value

File C:\ProgramData\Miniconda3\envs\t_env\lib\site-packages\dataclasses_json\core.py:220, in _support_extended_types(field_type, field_value) 218 else: 219 tz = datetime.now(timezone.utc).astimezone().tzinfo --> 220 res = datetime.fromtimestamp(field_value, tz=tz) 221 elif _issubclass_safe(field_type, Decimal): 222 res = (field_value 223 if isinstance(field_value, Decimal) 224 else Decimal(field_value))

TypeError: an integer is required (got type str)

theavey avatar Mar 04 '22 22:03 theavey