question

Upvotes
Accepted
5 4 3 4

ValueError: Columns must be same length as key

Hello team,

I'm getting an error when sending a request through Refinitiv Data Library

Environment: Codebook

RD Version: 1.0.0b16

Note: it seems TR.MUNIRating is causing the bug.

Note 2: the same request run's fine in EDAPI.

Request:

import refinitiv.data as rd
rd.open_session()

instruments = ['PH010907888=']
lfields  = [
        'TR.RiskCountry',
        'TR.RiskCountryCode',
        'TR.CDSRefEntCtryCode2',
        'TR.GR.Rating',
        'TR.MUNIRating',
        'TR.IssuerRating',
        'TR.FiFitchsRating',
        'TR.FiIssuerSPLongRating',
        'TR.FiIssuerFitchLongRating',
        'TR.FiSPRating',
        'TR.FiIndustrySubSectorDescription'
    ]
rd.get_data(
    universe=instruments,
    fields=lfields
)

Result:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_229/2241032370.py in <module>
     16         'TR.FiIndustrySubSectorDescription'
     17     ]
---> 18 rd.get_data(
     19     universe=instruments,
     20     fields=lfields

/opt/conda/lib/python3.8/site-packages/refinitiv/data/_fin_coder_layer/get_data.py in get_data(universe, fields, parameters, use_field_names_in_headers)
     73     if isinstance(universe, str):
     74         universe = [universe]
---> 75     return _get_data(
     76         _fundamental_data=fundamental_and_reference.Definition,
     77         _pricing_stream=Stream(universe=universe, fields=fields),

/opt/conda/lib/python3.8/site-packages/refinitiv/data/_fin_coder_layer/get_data.py in _get_data(_fundamental_data, _pricing_stream, **kwargs)
    175 
    176     columns = get_name_columns_without_datetime(result)
--> 177     result[columns] = result[columns].replace([pd.NaT, np.NaN], pd.NA)
    178 
    179     return result

/opt/conda/lib/python3.8/site-packages/pandas/core/frame.py in __setitem__(self, key, value)
   3598             self._setitem_frame(key, value)
   3599         elif isinstance(key, (Series, np.ndarray, list, Index)):
-> 3600             self._setitem_array(key, value)
   3601         elif isinstance(value, DataFrame):
   3602             self._set_item_frame_value(key, value)

/opt/conda/lib/python3.8/site-packages/pandas/core/frame.py in _setitem_array(self, key, value)
   3639                 check_key_length(self.columns, key, value)
   3640                 for k1, k2 in zip(key, value.columns):
-> 3641                     self[k1] = value[k2]
   3642 
   3643             elif not is_list_like(value):

/opt/conda/lib/python3.8/site-packages/pandas/core/frame.py in __setitem__(self, key, value)
   3600             self._setitem_array(key, value)
   3601         elif isinstance(value, DataFrame):
-> 3602             self._set_item_frame_value(key, value)
   3603         elif (
   3604             is_list_like(value)

/opt/conda/lib/python3.8/site-packages/pandas/core/frame.py in _set_item_frame_value(self, key, value)
   3727             len_cols = 1 if is_scalar(cols) else len(cols)
   3728             if len_cols != len(value.columns):
-> 3729                 raise ValueError("Columns must be same length as key")
   3730 
   3731             # align right-hand-side columns if self.columns

ValueError: Columns must be same length as key
pythonrefinitiv-data-platformrefinitiv-data-platform-librariescodebook
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
13.1k 61 39 63

Hi @mahjoub.faraj

I believe the issue has been resolved. Version 1.0.0b20 will be released very soon.

ahs.png

The above is tested with 1.0.0b19.


ahs.png (23.6 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
16.7k 42 12 19

I can also reproduce this issue with the RD library. It works with Eikon Data API and produces the correct result:

1660760275270.png


@pierre.faurel, @Olivier DAVANT, can you please advise on this bug.



1660760275270.png (15.6 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.