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

Running .institutional_holders give the following error - ValueError: time data "..." doesn't match format "%B %d, %Y", at position 1 #1685

Closed
Valachio opened this issue Sep 18, 2023 · 4 comments

Comments

@Valachio
Copy link

Describe bug

I was scraping the ticker ACST and getting institutional holders when I ran into this issue.

The issue can be replicated like this:

import yfinance
stock = yfinance.Ticker('ACST')
stock.institutional_holders # Gives error

The full error is:

ValueError: time data "Jun 29, 2023" doesn't match format "%B %d, %Y", at position 1. You might want to try:
    - passing `format` if your strings have a consistent format;
    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.

I'm using Python 3.11, and yfinance v0.2.28

Simple code that reproduces your problem

import yfinance
stock = yfinance.Ticker('ACST')
stock.institutional_holders # Gives error

Debug log

/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/yfinance/scrapers/holders.py:39: FutureWarning: Passing literal html to 'read_html' is deprecated and will be removed in a future version. To read from a literal string, wrap it in a 'StringIO' object.
holders = pd.read_html(resp.text)
Traceback (most recent call last):
File "", line 1, in
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/yfinance/ticker.py", line 114, in institutional_holders
return self.get_institutional_holders()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/yfinance/base.py", line 1662, in get_institutional_holders
data = self._holders.institutional
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/yfinance/scrapers/holders.py", line 26, in institutional
self._scrape(self.proxy)
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/yfinance/scrapers/holders.py", line 63, in _scrape
self._mutualfund['Date Reported'] = pd.to_datetime(
^^^^^^^^^^^^^^^
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 1112, in to_datetime
values = convert_listlike(arg._values, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 488, in _convert_listlike_datetimes
return _array_strptime_with_fallback(arg, name, utc, format, exact, errors)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jack/Projects/ais/aisenv/lib/python3.11/site-packages/pandas/core/tools/datetimes.py", line 519, in _array_strptime_with_fallback
result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "strptime.pyx", line 534, in pandas._libs.tslibs.strptime.array_strptime
File "strptime.pyx", line 355, in pandas._libs.tslibs.strptime.array_strptime
ValueError: time data "Jun 29, 2023" doesn't match format "%B %d, %Y", at position 1. You might want to try:
- passing format if your strings have a consistent format;
- passing format='ISO8601' if your strings are all ISO8601 but not necessarily in exactly the same format;
- passing format='mixed', and the format will be inferred for each element individually. You might want to use dayfirst alongside this.

Bad data proof

No response

yfinance version

0.2.28

Python version

3.11

Operating system

M2 Macbook Air; Ventura 13.1

@rickturner2001
Copy link
Contributor

I am unable to reproduct this on my machine. Are you still facing issues with this?

@NathanaelV
Copy link

I had the same error:

FutureWarning: Passing literal html to 'read_html' is deprecated and will be removed in a future version. To read from a literal string, wrap it in a 'StringIO' object.

@speedbits
Copy link

I am getting the same error. I am using python 3.9 version on windows 10.

mikez added a commit to mikez/yfinance that referenced this issue Nov 9, 2023
…recated"

This addresses ranaroussi#1685 (`institutional_holders`) and also `get_earnings_dates()`.

Pandas issue is found here:
pandas-dev/pandas#53767
and the change in code here:
https://github.com/pandas-dev/pandas/blob/5cedf87cccd77c7b4b6aaa64bfec98b32b512f68/pandas/io/html.py#L1238

As for legacy Python 2.7 support: `io.StringIO` seems to be supported in
the versions I tested. See https://docs.python.org/2/library/io.html
@bot-unit
Copy link

@ValueRaider Close, please. Implemented at #1772

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

6 participants