unexpected IndexError

I am getting a really strange error when executing following lines

IndexError: index 2 is out of bounds for axis 0 with size 2

This is unexpected to me because it only happens to this 2 RICs. Anyone has any clue on why these 2 RICs are so special?


rics = ['005110.KS', '005160.KQ']
df2 = ek.get_timeseries(rics=rics, start_date='2021-04-06', end_date='2021-04-06', corax='unadjusted')
df2.stack(level=-2)

Best Answer

  • @Max.Zhu Yes it took me a while! So the issue here seems to be something with the stack routine that doesn't like integer values. So if you look at df2.info() for the Korean stocks that are causing issues - they are of int64 type:

    image

    Now if I change the dataframe Dtype from int64 to float then try the stack:

    df3 = df2.astype(float).copy()
    df3.stack(level=-2)

    image

    It all works fine, So I believe this is some DType issue with Pandas' stack routine. I will also speak to the dev team to check if the type conversions at our end are all correct.

    I also checked with some other RICs ['VOD.L','BARC.L'] and they returned a mixture of floats and ints and it all worked correctly. I hope this can help.


Answers

  • Hi @Max.Zhu,

    This issue isn't linked to rics.

    When you request more than 1 ric, the result is not a pure multi-level indexed Dataframe but a concatenation of multi-level indexed Dataframe, that's why you can't stack it.

    If you iterate on rics, you can stack each sub-Dataframe:

    for ric in rics:
    print(ric)
    df = df2[ric]
    print(df)
    print("________________")
    df = df.stack()
    print(df)

    Result:

    005110.KS
                HIGH   LOW  OPEN  CLOSE  VOLUME
    Date                                       
    2021-04-06  1275  1240  1255   1255  587997
    ________________
    Date              
    2021-04-06  HIGH        1275
                LOW         1240
                OPEN        1255
                CLOSE       1255
                VOLUME    587997
    dtype: Int64
    005160.KQ
                HIGH   LOW  OPEN  CLOSE  VOLUME
    Date                                       
    2021-04-06  3670  3590  3670   3650  162384
    ________________
    Date              
    2021-04-06  HIGH        3670
                LOW         3590
                OPEN        3670
                CLOSE       3650
                VOLUME    162384
    dtype: Int64

    Thank you for your feedback, we'll plan to fix it.

  • That's in fact exactly what I did offline to workaround the issue...


    Thanks for confirming this! It will be good if Eikon API can do the conversion automatically.