Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

jobs:
lint:
name: Lint with Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install ruff
run: pip install ruff

- name: Run ruff check
run: ruff check .

- name: Run ruff format check
run: ruff format --check .

test:
name: Test with Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov

- name: Install package
run: pip install .

- name: Run tests
run: pytest tests/ -v --tb=short
29 changes: 12 additions & 17 deletions pykrx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import importlib.resources as resources
import platform
import matplotlib.pyplot as plt

import matplotlib.font_manager as fm
import importlib.resources as resources
from . import bond
from . import stock
import matplotlib.pyplot as plt

from . import bond, stock

os = platform.system()

if os == "Darwin":
plt.rc('font', family="AppleGothic")
plt.rc("font", family="AppleGothic")

else:
with resources.path('pykrx', 'NanumBarunGothic.ttf') as font_path:
fe = fm.FontEntry(
fname=str(font_path),
name='NanumBarunGothic'
)
with resources.path("pykrx", "NanumBarunGothic.ttf") as font_path:
fe = fm.FontEntry(fname=str(font_path), name="NanumBarunGothic")
fm.fontManager.ttflist.insert(0, fe)
plt.rc('font', family=fe.name)
plt.rc("font", family=fe.name)

plt.rcParams['axes.unicode_minus'] = False
plt.rcParams["axes.unicode_minus"] = False

__all__ = [
'bond',
'stock'
]
__all__ = ["bond", "stock"]

__version__ = '1.0.51'
__version__ = "1.0.51"
2 changes: 1 addition & 1 deletion pykrx/bond/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .bond import *
from .bond import *
7 changes: 5 additions & 2 deletions pykrx/bond/bond.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from sqlite3 import NotSupportedError
from pykrx.website import krx

from pandas import DataFrame

from pykrx.website import krx


def get_otc_treasury_yields(*args) -> DataFrame:
"""장외 일자별 채권수익률
Expand Down Expand Up @@ -63,7 +65,8 @@ def get_otc_treasury_yields(*args) -> DataFrame:
df = krx.bond.get_otc_treasury_yields_by_ticker(args[0])
if df.empty:
target_date = krx.get_nearest_business_day_in_a_week(
date=args[0], prev=True)
date=args[0], prev=True
)
df = krx.get_otc_treasury_yields_by_ticker(target_date)
elif len(args) == 3:
df = krx.bond.get_otc_treasury_yields_by_date(*args)
Expand Down
2 changes: 1 addition & 1 deletion pykrx/stock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .stock_api import *
from .future_api import *
from .stock_api import *
19 changes: 10 additions & 9 deletions pykrx/stock/future_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pykrx.website import krx
import datetime
from pandas import DataFrame
import re

from pandas import DataFrame

from pykrx.website import krx

yymmdd = re.compile(r"\d{4}[-/]?\d{2}[-/]?\d{2}")


Expand Down Expand Up @@ -74,25 +76,24 @@ def get_future_ohlcv(*args, **kwargs):
""" # pylint: disable=line-too-long # noqa: E501

dates = list(filter(yymmdd.match, [str(x) for x in args]))
if len(dates) == 2 or ('fromdate' in kwargs and
'todate' in kwargs):
if len(dates) == 2 or ("fromdate" in kwargs and "todate" in kwargs):
raise NotImplementedError
# return get_future_ohlcv_by_date(*args, **kwargs)
else:
return get_future_ohlcv_by_ticker(*args, **kwargs)


def get_future_ohlcv_by_ticker(date: str, prod: str, alternative: bool = False,
prev: bool = True) -> DataFrame:
def get_future_ohlcv_by_ticker(
date: str, prod: str, alternative: bool = False, prev: bool = True
) -> DataFrame:
if isinstance(date, datetime.datetime):
date = krx.datetime2string(date)

date = date.replace("-", "")

df = krx.get_future_ohlcv_by_ticker(date, prod)
if df.empty and alternative:
target_date = krx.get_nearest_business_day_in_a_week(
date=date, prev=prev)
target_date = krx.get_nearest_business_day_in_a_week(date=date, prev=prev)
df = krx.get_future_ohlcv_by_ticker(target_date, prod)
return df

Expand All @@ -104,5 +105,5 @@ def get_future_ohlcv_by_ticker(date: str, prod: str, alternative: bool = False,
# names = get_future_ticker_name('KRDRVFUEST')
# print(names)

df = get_future_ohlcv('20220902', 'KRDRVFUEST')
df = get_future_ohlcv("20220902", "KRDRVFUEST")
print(df)
Loading