Skip to content

Commit 54231b1

Browse files
committed
Fix the numpy version incompatible bug
1 parent 2fcadfe commit 54231b1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

qlib/data/storage/file_storage.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,22 @@ def _freq_file(self) -> str:
102102
self._freq_file_cache = freq
103103
return self._freq_file_cache
104104

105-
def _read_calendar(self, skip_rows: int = 0, n_rows: int = None) -> List[CalVT]:
105+
def _read_calendar(self) -> List[CalVT]:
106+
# NOTE:
107+
# if we want to accelerate partial reading calendar
108+
# we can add parameters like `skip_rows: int = 0, n_rows: int = None` to the interface.
109+
# Currently, it is not supported for the txt-based calendar
110+
106111
if not self.uri.exists():
107112
self._write_calendar(values=[])
108-
with self.uri.open("rb") as fp:
109-
return [
110-
str(x)
111-
for x in np.loadtxt(fp, str, skiprows=skip_rows, max_rows=n_rows, delimiter="\n", encoding="utf-8")
112-
]
113+
114+
with self.uri.open("r") as fp:
115+
res = []
116+
for line in fp.readlines():
117+
line = line.strip()
118+
if len(line) > 0:
119+
res.append(line)
120+
return res
113121

114122
def _write_calendar(self, values: Iterable[CalVT], mode: str = "wb"):
115123
with self.uri.open(mode=mode) as fp:

0 commit comments

Comments
 (0)