question

Upvotes
Accepted
3 0 0 1

FYE Date; does not return a date

When I run the below; it does not return a date.


fye_date = ds.get_data(tickers='R:ABGJ', fields=['WC05350'], kind=1, start = '2005-12-31', end = '2020-07-31', freq = 'Y')

fye_date



How does one interpret this as a date in python?

datastream-apidsws-api
capture.png (30.5 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.

@Josiah

Hi,

Thank you for your participation in the forum.

Is the reply below satisfactory in answering your question?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS


1 Answer

· Write an Answer
Upvotes
Accepted
79.2k 251 52 74

@Josiah

It is expected behavior as mentioned in this thread. I found the code used to convert JSON date format to Python date in the DataStreamDSWS library.

import re
import datetime
import pytz
import traceback

def get_Date(jsonDate):
        try:            
            match = re.match(r"^(/Date\()(-?\d*)([+-])(..)(..)(\)/)", jsonDate)
            if match:
                
                d = float(match.group(2))
                ndate = datetime.datetime(1970,1,1) + datetime.timedelta(seconds=float(d)/1000)
                utcdate = pytz.UTC.fromutc(ndate).strftime('%Y-%m-%d')
                return utcdate
            else:
                raise Exception("Invalid JSON Date")
        except Exception:
            print("_get_token : Exception Occured")
            print(traceback.sys.exc_info())
            print(traceback.print_exc(limit=2))
            return None

Then, I used this method to convert the WC05350 column.

fye_date = ds.get_data(tickers='R:ABGJ', fields=['WC05350'], kind=1, start = '2005-12-31', end = '2020-07-31', freq = 'Y')
fye_date[('R:ABGJ', 'WC05350')] = list(map(get_Date, fye_date[('R:ABGJ', 'WC05350')].values))
fye_date
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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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