question

Upvotes
Accepted
3 0 0 0

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 5.0 MiB each and 10.0 MiB total.

1 Answer

Upvotes
Accepted
38.1k 71 35 53

@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 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea