pandas-datareader icon indicating copy to clipboard operation
pandas-datareader copied to clipboard

OECD / MEI_CLI - Out of bounds nanosecond timestamp (objects_to_datetime64ns)

Open Jahoe opened this issue 4 years ago • 0 comments

When calling MEI_CLI it looks like there's some parsing issue with the data set. Given the code below:

import pandas_datareader.data as dr
dataset = dr.DataReader('MEI_CLI', 'oecd')
print(dataset.columns)

or using the snippet from the docs:

import pandas_datareader as dr
dataset = dr.oecd.OECDReader('MEI_CLI')
dataset.read()
print (dataset.read())

We get the following output:

Traceback (most recent call last):
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\arrays\datetimes.py", line 2085, in objects_to_datetime64ns
    values, tz_parsed = conversion.datetime_to_datetime64(data)
  File "pandas\_libs\tslibs\conversion.pyx", line 350, in pandas._libs.tslibs.conversion.datetime_to_datetime64
TypeError: Unrecognized value type: <class 'str'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\test.py", line 2, in <module>
    dataset = dr.DataReader('MEI_CLI', 'oecd')
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\util\_decorators.py", line 199, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas_datareader\data.py", line 475, in DataReader
    return OECDReader(
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas_datareader\base.py", line 100, in read
    return self._read_one_data(self.url, self.params)
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas_datareader\base.py", line 112, in _read_one_data
    return self._read_lines(out)
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas_datareader\oecd.py", line 27, in _read_lines
    df = read_jsdmx(out)
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas_datareader\io\jsdmx.py", line 45, in read_jsdmx
    index = _parse_dimensions(structure["dimensions"]["observation"])
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas_datareader\io\jsdmx.py", line 108, in _parse_dimensions
    values = pd.DatetimeIndex(values)
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\datetimes.py", line 307, in __new__
    dtarr = DatetimeArray._from_sequence_not_strict(
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\arrays\datetimes.py", line 326, in _from_sequence_not_strict
    subarr, tz, inferred_freq = sequence_to_dt64ns(
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\arrays\datetimes.py", line 1973, in sequence_to_dt64ns
    data, inferred_tz = objects_to_datetime64ns(
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\arrays\datetimes.py", line 2090, in objects_to_datetime64ns
    raise e
  File "C:\Users\jahoe\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\arrays\datetimes.py", line 2075, in objects_to_datetime64ns
    result, tz_parsed = tslib.array_to_datetime(
  File "pandas\_libs\tslib.pyx", line 364, in pandas._libs.tslib.array_to_datetime
  File "pandas\_libs\tslib.pyx", line 586, in pandas._libs.tslib.array_to_datetime
  File "pandas\_libs\tslib.pyx", line 582, in pandas._libs.tslib.array_to_datetime
  File "pandas\_libs\tslib.pyx", line 537, in pandas._libs.tslib.array_to_datetime
  File "pandas\_libs\tslibs\conversion.pyx", line 507, in pandas._libs.tslibs.conversion.convert_datetime_to_tsobject
  File "pandas\_libs\tslibs\np_datetime.pyx", line 113, in pandas._libs.tslibs.np_datetime.check_dts_bounds
pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-01-21 00:00:00

Currently can't find a work around for the issue. However manually parsing the JSON from the MEI_CLI URL does work.

Jahoe avatar Mar 31 '21 09:03 Jahoe