Type checking in Python

At several points in pyeikon 1.0.0 it appears the API is not using Python best practices for type checking. For example, in time_series.to_datetime:

if type(date_value) is timedelta:
...
if type(date_value) in (datetime, date):

These should really be:

if isinstance(date_value, timedelta):
...
if isinstance(date_value, (datetime, date)):

As is, for example, use of a pandas Timestamp as the start_date or end_date parameter fails, even though pandas.Timestamp is a subclass of datetime. This is especially frustrating as it means that the start_date parameter can't be set to, say, df.index[0] from a df that was itself returned by the get_timeseries API.

Similarly, get_data and get_timeseries currently require the rics parameter to be a list of strings. These should really take any iterable. If you need a list (for example to guarantee order), you should cast it internally. As-is you cannot, for example, pass a generator, a pandas Index, or numpy array to get_data or get_timeseries which is similarly frustrating (you cannot, for example, directly take the values of a query for index members and pass them into get_data without casting).

Answers