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

stock.get_market_ohlcv / 'OverflowError: Python int too large to convert to C long 오류 #180

Open
emoochin opened this issue May 2, 2024 · 4 comments
Assignees
Labels
bug Something isn't working closing-candidate help wanted Extra attention is needed waiting-for-user-response

Comments

@emoochin
Copy link

emoochin commented May 2, 2024

stock.get_market_ohlcv('20220924', '20240223', '032800') # 판타지오 032800
위 코드 실행 시 'OverflowError: Python int too large to convert to C long 오류가 발생합니다.

특이한 점은 데이터 조회 일자에 따라 오류가 발생하기도 하고 정상 동작하기도 합니다.
금일 실행 기준으로,

  • 20220924 이전의 데이터에 대해 조회하면 에러가 발생합니다.
  • stock.get_market_ohlcv('20220925', '20240223', '032800') 이런 식으로 20220925 이후의 날짜에 대해 조회하면 정상 동작합니다.

코드 실행 환경은 아래와 같습니다.

  • 윈도우 10
  • anaconda 가상 환경
  • 가상 환경 파이썬 버전 3.9.19

해결법을 찾지 못하여 문의 드립니다.

@mr-yoo mr-yoo self-assigned this Jul 14, 2024
@mr-yoo
Copy link
Collaborator

mr-yoo commented Jul 14, 2024

모듈 버전을 확인해 주세요.

import pykrx
print(pykrx.__version__)

현재 최신은 1.0.46 입니다. 과거 버전이라면 업데이트 해 주시구요.
pip install -U pykrx

@mr-yoo mr-yoo added help wanted Extra attention is needed waiting-for-user-response labels Jul 14, 2024
@Yukariko
Copy link

Yukariko commented Jul 15, 2024

@mr-yoo 저 역시 같은 오류가 나오는데요, python 3.12.4, 모듈 버전은 1.0.47입니다.

@Yukariko
Copy link

Yukariko commented Jul 15, 2024

Traceback (most recent call last):
  File "/Users/yukariko/git/trading/database.py", line 10, in <module>
    df = stock.get_market_ohlcv("20110101", "20110201", ticker)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pykrx/stock/stock_api.py", line 189, in get_market_ohlcv
    return get_market_ohlcv_by_date(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pykrx/stock/stock_api.py", line 231, in get_market_ohlcv_by_date
    df = naver.get_market_ohlcv_by_date(fromdate , todate, ticker)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pykrx/website/naver/wrap.py", line 28, in get_market_ohlcv_by_date
    df = df.astype(np.int32)
         ^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/generic.py", line 6643, in astype
    new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 430, in astype
    return self.apply(
           ^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 363, in apply
    applied = getattr(b, f)(**kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/internals/blocks.py", line 758, in astype
    new_values = astype_array_safe(values, dtype, copy=copy, errors=errors)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 237, in astype_array_safe
    new_values = astype_array(values, dtype, copy=copy)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 182, in astype_array
    values = _astype_nansafe(values, dtype, copy=copy)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yukariko/.venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 133, in _astype_nansafe
    return arr.astype(dtype, copy=True)
OverflowError: Python integer 3929287705 out of bounds for int32

trace 첨부합니다.

mr-yoo added a commit that referenced this issue Jul 15, 2024
@mr-yoo
Copy link
Collaborator

mr-yoo commented Jul 15, 2024

Naver 에서 데이터를 스크래핑한 결과에 32비트로 표현 불가능한 큰수가 있는 것을 확인했습니다. becb471 커밋에서 64비트로 변경하도록 수정했습니다.

@mr-yoo mr-yoo added bug Something isn't working closing-candidate labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closing-candidate help wanted Extra attention is needed waiting-for-user-response
Projects
None yet
Development

No branches or pull requests

3 participants