Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack trace when loading category 33845 #13

Open
boreshkinai opened this issue Jul 7, 2023 · 1 comment
Open

Stack trace when loading category 33845 #13

boreshkinai opened this issue Jul 7, 2023 · 1 comment

Comments

@boreshkinai
Copy link

fr = Fred(api_key=api_key,response_type='df')
fr.category.series(33845, params={'limit':1000, 'offset': 0})

TypeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/tools/datetimes.py in _convert_listlike(arg, box, format, name, tz)
376 try:
--> 377 values, tz = conversion.datetime_to_datetime64(arg)
378 return DatetimeIndex._simple_new(values, name=name, tz=tz)

pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion.datetime_to_datetime64()

TypeError: Unrecognized value type: <class 'str'>

During handling of the above exception, another exception occurred:

OutOfBoundsDatetime Traceback (most recent call last)
/tmp/ipykernel_333/1514929282.py in
1 fr = get_fred_api()
2
----> 3 fr.category.series(33845, params={'limit':RESPONSE_LIMIT, 'offset': 0})

/usr/local/lib/python3.7/dist-packages/fred/utils/init.py in _wrapped(*args, **kwargs)
15 if p in kwargs:
16 params[p] = kwargs.pop(p)
---> 17 return func(*args,params=params,**kwargs)
18 return _wrapped
19 return _wrapper

/usr/local/lib/python3.7/dist-packages/fred/clients/categories.py in series(self, category_id, response_type, params)
93 response_type = response_type if response_type else self.response_type
94 if response_type != 'xml': params['file_type'] = 'json'
---> 95 response = _get_request(self.url_root,self.api_key,path,response_type,params)
96 return response
97

/usr/local/lib/python3.7/dist-packages/fred/helpers/init.py in _get_request(url_root, api_key, path, response_type, params)
115 url = _url_builder(url_root,api_key,path,params)
116 content = _fetch(url)
--> 117 response = _dispatch(response_type)(content)
118 return response

/usr/local/lib/python3.7/dist-packages/fred/helpers/init.py in _data_frame(content)
56 key = [x for x in response.keys() if x in c.response_data][0]
57 frame = DataFrame(response[key])
---> 58 final_frame = _convert(frame)
59 return final_frame
60

/usr/local/lib/python3.7/dist-packages/fred/helpers/init.py in _convert(frame)
37 for column in frame:
38 if column in c.dates:
---> 39 frame[column] = frame[column].astype('datetime64')
40 return frame
41

/usr/local/lib/python3.7/dist-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
176 else:
177 kwargs[new_arg_name] = new_arg_value
--> 178 return func(*args, **kwargs)
179 return wrapper
180 return _deprecate_kwarg

/usr/local/lib/python3.7/dist-packages/pandas/core/generic.py in astype(self, dtype, copy, errors, **kwargs)
4999 # else, only a single dtype is given
5000 new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors,
-> 5001 **kwargs)
5002 return self._constructor(new_data).finalize(self)
5003

/usr/local/lib/python3.7/dist-packages/pandas/core/internals.py in astype(self, dtype, **kwargs)
3712
3713 def astype(self, dtype, **kwargs):
-> 3714 return self.apply('astype', dtype=dtype, **kwargs)
3715
3716 def convert(self, **kwargs):

/usr/local/lib/python3.7/dist-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
3579
3580 kwargs['mgr'] = self
-> 3581 applied = getattr(b, f)(**kwargs)
3582 result_blocks = _extend_blocks(applied, result_blocks)
3583

/usr/local/lib/python3.7/dist-packages/pandas/core/internals.py in astype(self, dtype, copy, errors, values, **kwargs)
573 def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
574 return self._astype(dtype, copy=copy, errors=errors, values=values,
--> 575 **kwargs)
576
577 def _astype(self, dtype, copy=False, errors='raise', values=None,

/usr/local/lib/python3.7/dist-packages/pandas/core/internals.py in _astype(self, dtype, copy, errors, values, klass, mgr, **kwargs)
662
663 # _astype_nansafe works fine with 1-d only
--> 664 values = astype_nansafe(values.ravel(), dtype, copy=True)
665 values = values.reshape(self.shape)
666

/usr/local/lib/python3.7/dist-packages/pandas/core/dtypes/cast.py in astype_nansafe(arr, dtype, copy)
714 elif is_datetime64_dtype(dtype):
715 from pandas import to_datetime
--> 716 return astype_nansafe(to_datetime(arr).values, dtype, copy=copy)
717 elif is_timedelta64_dtype(dtype):
718 from pandas import to_timedelta

/usr/local/lib/python3.7/dist-packages/pandas/core/tools/datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, box, format, exact, unit, infer_datetime_format, origin, cache)
465 result = _convert_and_box_cache(arg, cache_array, box, errors)
466 else:
--> 467 result = _convert_listlike(arg, box, format)
468 else:
469 result = _convert_listlike(np.array([arg]), box, format)[0]

/usr/local/lib/python3.7/dist-packages/pandas/core/tools/datetimes.py in _convert_listlike(arg, box, format, name, tz)
378 return DatetimeIndex._simple_new(values, name=name, tz=tz)
379 except (ValueError, TypeError):
--> 380 raise e
381
382 if arg is None:

/usr/local/lib/python3.7/dist-packages/pandas/core/tools/datetimes.py in _convert_listlike(arg, box, format, name, tz)
366 dayfirst=dayfirst,
367 yearfirst=yearfirst,
--> 368 require_iso8601=require_iso8601
369 )
370

pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()

pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()

pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()

pandas/_libs/tslib.pyx in pandas._libs.tslib.array_to_datetime()

pandas/_libs/tslibs/np_datetime.pyx in pandas._libs.tslibs.np_datetime.check_dts_bounds()

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1270-01-01 00:00:00

@boreshkinai
Copy link
Author

boreshkinai commented Jul 7, 2023

The issue is here:

/usr/local/lib/python3.7/dist-packages/fred/helpers/init.py in _convert(frame)
37 for column in frame:
38 if column in c.dates:
---> 39 frame[column] = frame[column].astype('datetime64')
40 return frame
41

I think the conversion could be best done using safe method such as

frame[column] = pd.to_datetime(frame[column], errors = 'coerce')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant