Skip to content

Commit d62717b

Browse files
committed
Filter by dates
1 parent f6d1eae commit d62717b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas_datareader/naver.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from datetime import datetime
12
from xml.etree import ElementTree
23

4+
import numpy as np
35
from pandas import DataFrame, to_datetime
46
from pandas_datareader.base import _DailyBaseReader
57

@@ -47,7 +49,13 @@ def url(self):
4749
return "https://fchart.stock.naver.com/sise.nhn"
4850

4951
def _get_params(self, symbol):
50-
params = {"symbol": symbol, "timeframe": "day", "count": 500, "requestType": 0}
52+
# NOTE: The server does not take start, end dates as inputs; it only
53+
# takes the number of past days as an input. To circumvent this
54+
# pitfall, we calculate the number of business days between self.start
55+
# and the current date. And then before returning the final result
56+
# (from _read_one_data()) we filter by self.end.
57+
days = np.busday_count(self.start.date(), datetime.now().date())
58+
params = {"symbol": symbol, "timeframe": "day", "count": days, "requestType": 0}
5159
return params
5260

5361
def _read_one_data(self, url, params):
@@ -62,7 +70,8 @@ def _read_one_data(self, url, params):
6270
)
6371
prices["Date"] = to_datetime(prices["Date"])
6472

65-
return prices
73+
# NOTE: See _get_params() for explanations.
74+
return prices[(prices["Date"] >= self.start) & (prices["Date"] <= self.end)]
6675

6776
def _parse_xml_response(self, xml_content):
6877
"""Parses XML response from the server.

0 commit comments

Comments
 (0)