ValueError: datetime64/timedelta64 values and dtype must have a unit specified

I get an error when trying to retrieve news headlines with Python API. The error only seems to occur on certain time ranges. For example, this works:
import eikon as ek
df = ek.get_news_headlines('Topic:ESG AND Language:LEN', date_from='2022-01-01', date_to='2022-12-01', count=100)
But this does not work (the only difference is the time range):
import eikon as ek
df = ek.get_news_headlines('Topic:ESG AND Language:LEN', date_from='2020-01-01', date_to='2020-12-01', count=100)
This is the error I receive:
Traceback (most recent call last):
File "...\PycharmProjects\refinitivsentiment\main.py", line 12, in <module>
df = ek.get_news_headlines(date_from='2020-01-01',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\eikon\news_request.py", line 126, in get_news_headlines
return get_data_frame(result)
^^^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\eikon\news_request.py", line 144, in get_data_frame
headlines_dataframe = pd.DataFrame([], numpy.array(first_created, dtype='datetime64'), Headline_Selected_Fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\frame.py", line 771, in __init__
mgr = dict_to_mgr(
^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\internals\construction.py", line 450, in dict_to_mgr
index = ensure_index(index)
^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py", line 7333, in ensure_index
return Index._with_infer(index_like, copy=copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py", line 716, in _with_infer
result = cls(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py", line 486, in __new__
result = klass(data, copy=copy, name=name, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\datetimes.py", line 359, in __new__
dtarr = DatetimeArray._from_sequence_not_strict(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\arrays\datetimes.py", line 307, in _from_sequence_not_strict
subarr, tz, inferred_freq = _sequence_to_dt64ns(
^^^^^^^^^^^^^^^^^^^^
File "...\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\arrays\datetimes.py", line 2091, in _sequence_to_dt64ns
data = astype_overflowsafe(data, dtype=DT64NS_DTYPE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pandas\_libs\tslibs\np_datetime.pyx", line 288, in pandas._libs.tslibs.np_datetime.astype_overflowsafe
File "pandas\_libs\tslibs\np_datetime.pyx", line 321, in pandas._libs.tslibs.np_datetime.astype_overflowsafe
ValueError: datetime64/timedelta64 values and dtype must have a unit specified
Do you have any ideas what could be causing the error?
Best Answer
-
Hi @essi.rajala ,
Thank you for your question. According to the Eikon Data API Usage and Limits Guideline, The depth of news headline history is 15 month, that is why you don't receive the data for 2020.
Hope this helps.
Best regards,
Haykaz
0
Answers
-
Hi @essi.rajala ,
I'm sorry to hear that you're facing an issue. However, I was not able to reproduce the issue in my local environment or CodeBook, with the same request.
It seems from the error that it does not originate with the eikon library, but rather with one of the eikon dependencies, suspecting NumPy or pandas.
Would suggest verifying the versions of pandas and NumPy against CodeBook versions as mentioned in this thread
To be of help, below are the current version of the libraries mentioned in the Codebook app
- Eikon version 1.1.14
- Pandas version 1.3.5
- NumPy version 1.22.4
- Python 3.8.15
Plus, refer to the Eikon Data API Usage and Limits Guideline, the depth of news headlines is 15 months.
get_news_headlines: The current limit value (10-Oct-2019) is 100 headlines per request. The depth of history is 15 month.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 616 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 556 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 652 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛