rquote 0.4.1__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. {rquote-0.4.1 → rquote-0.4.2}/PKG-INFO +2 -2
  2. {rquote-0.4.1 → rquote-0.4.2}/README.md +1 -1
  3. {rquote-0.4.1 → rquote-0.4.2}/pyproject.toml +1 -1
  4. {rquote-0.4.1 → rquote-0.4.2}/rquote/cache/persistent.py +58 -57
  5. {rquote-0.4.1 → rquote-0.4.2}/rquote.egg-info/PKG-INFO +2 -2
  6. {rquote-0.4.1 → rquote-0.4.2}/rquote/__init__.py +0 -0
  7. {rquote-0.4.1 → rquote-0.4.2}/rquote/api/__init__.py +0 -0
  8. {rquote-0.4.1 → rquote-0.4.2}/rquote/api/lists.py +0 -0
  9. {rquote-0.4.1 → rquote-0.4.2}/rquote/api/price.py +0 -0
  10. {rquote-0.4.1 → rquote-0.4.2}/rquote/api/stock_info.py +0 -0
  11. {rquote-0.4.1 → rquote-0.4.2}/rquote/api/tick.py +0 -0
  12. {rquote-0.4.1 → rquote-0.4.2}/rquote/cache/__init__.py +0 -0
  13. {rquote-0.4.1 → rquote-0.4.2}/rquote/cache/base.py +0 -0
  14. {rquote-0.4.1 → rquote-0.4.2}/rquote/cache/memory.py +0 -0
  15. {rquote-0.4.1 → rquote-0.4.2}/rquote/config.py +0 -0
  16. {rquote-0.4.1 → rquote-0.4.2}/rquote/data_sources/__init__.py +0 -0
  17. {rquote-0.4.1 → rquote-0.4.2}/rquote/data_sources/base.py +0 -0
  18. {rquote-0.4.1 → rquote-0.4.2}/rquote/data_sources/sina.py +0 -0
  19. {rquote-0.4.1 → rquote-0.4.2}/rquote/data_sources/tencent.py +0 -0
  20. {rquote-0.4.1 → rquote-0.4.2}/rquote/exceptions.py +0 -0
  21. {rquote-0.4.1 → rquote-0.4.2}/rquote/factors/__init__.py +0 -0
  22. {rquote-0.4.1 → rquote-0.4.2}/rquote/factors/technical.py +0 -0
  23. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/__init__.py +0 -0
  24. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/base.py +0 -0
  25. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/cn_stock.py +0 -0
  26. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/factory.py +0 -0
  27. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/future.py +0 -0
  28. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/hk_stock.py +0 -0
  29. {rquote-0.4.1 → rquote-0.4.2}/rquote/markets/us_stock.py +0 -0
  30. {rquote-0.4.1 → rquote-0.4.2}/rquote/parsers/__init__.py +0 -0
  31. {rquote-0.4.1 → rquote-0.4.2}/rquote/parsers/kline.py +0 -0
  32. {rquote-0.4.1 → rquote-0.4.2}/rquote/plots.py +0 -0
  33. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils/__init__.py +0 -0
  34. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils/date.py +0 -0
  35. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils/helpers.py +0 -0
  36. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils/http.py +0 -0
  37. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils/logging.py +0 -0
  38. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils/web.py +0 -0
  39. {rquote-0.4.1 → rquote-0.4.2}/rquote/utils.py +0 -0
  40. {rquote-0.4.1 → rquote-0.4.2}/rquote.egg-info/SOURCES.txt +0 -0
  41. {rquote-0.4.1 → rquote-0.4.2}/rquote.egg-info/dependency_links.txt +0 -0
  42. {rquote-0.4.1 → rquote-0.4.2}/rquote.egg-info/requires.txt +0 -0
  43. {rquote-0.4.1 → rquote-0.4.2}/rquote.egg-info/top_level.txt +0 -0
  44. {rquote-0.4.1 → rquote-0.4.2}/setup.cfg +0 -0
  45. {rquote-0.4.1 → rquote-0.4.2}/tests/test_api.py +0 -0
  46. {rquote-0.4.1 → rquote-0.4.2}/tests/test_cache.py +0 -0
  47. {rquote-0.4.1 → rquote-0.4.2}/tests/test_config.py +0 -0
  48. {rquote-0.4.1 → rquote-0.4.2}/tests/test_exceptions.py +0 -0
  49. {rquote-0.4.1 → rquote-0.4.2}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
5
5
  Requires-Python: >=3.9.0
6
6
  Description-Content-Type: text/markdown
@@ -18,7 +18,7 @@ Requires-Dist: duckdb>=0.9.0; extra == "persistent"
18
18
 
19
19
  ## 版本信息
20
20
 
21
- 当前版本:**0.4.1**
21
+ 当前版本:**0.4.2**
22
22
 
23
23
  ## 主要特性
24
24
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 版本信息
6
6
 
7
- 当前版本:**0.4.1**
7
+ 当前版本:**0.4.2**
8
8
 
9
9
  ## 主要特性
10
10
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rquote"
7
- version = "0.4.1"
7
+ version = "0.4.2"
8
8
  description = "Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch"
9
9
  readme = "README.md"
10
10
  # requires-python = ">=3.6.1" # duckdb requires higher python version
@@ -232,7 +232,7 @@ class PersistentCache(Cache):
232
232
  freq: str, fq: str) -> Optional[Tuple[str, str, pd.DataFrame]]:
233
233
  """从 duckdb 获取数据"""
234
234
  result = self.conn.execute("""
235
- SELECT name, data, earliest_date, latest_date, expire_at
235
+ SELECT name, data, expire_at
236
236
  FROM cache_data
237
237
  WHERE cache_key = ?
238
238
  """, [base_key]).fetchone()
@@ -240,7 +240,7 @@ class PersistentCache(Cache):
240
240
  if not result:
241
241
  return None
242
242
 
243
- name, data_blob, earliest_date, latest_date, expire_at = result
243
+ name, data_blob, expire_at = result
244
244
 
245
245
  # 检查过期
246
246
  if self.ttl and expire_at:
@@ -253,44 +253,44 @@ class PersistentCache(Cache):
253
253
  import pickle
254
254
  df = pickle.loads(data_blob)
255
255
 
256
- # 获取缓存数据的日期范围
257
- cached_earliest = self._parse_date(earliest_date)
258
- cached_latest = self._parse_date(latest_date)
256
+ # 确保索引是 DatetimeIndex
257
+ if not isinstance(df.index, pd.DatetimeIndex):
258
+ try:
259
+ df.index = pd.to_datetime(df.index)
260
+ except (ValueError, TypeError):
261
+ return None
262
+
263
+ if df.empty:
264
+ return None
259
265
 
260
- # 如果请求的日期范围完全在缓存范围内,直接返回过滤后的数据
266
+ # 直接从 DataFrame 索引获取实际的日期范围
267
+ cached_earliest = df.index.min()
268
+ cached_latest = df.index.max()
269
+
270
+ # 解析请求的日期范围
261
271
  request_sdate = self._parse_date(sdate) if sdate else None
262
272
  request_edate = self._parse_date(edate) if edate else None
263
273
 
264
- # 检查是否有重叠
265
- if request_edate and cached_earliest and request_edate < cached_earliest:
274
+ # 检查是否有重叠:如果请求的日期范围与缓存数据有重叠,就返回过滤后的数据
275
+ # 注意:即使缓存中有部分数据,也应该返回(让上层决定是否需要扩展)
276
+ has_overlap = True
277
+ if request_edate and request_edate < cached_earliest:
266
278
  # 请求的结束日期早于缓存的最早日期,无重叠
267
- return None
268
- if request_sdate and cached_latest and request_sdate > cached_latest:
279
+ has_overlap = False
280
+ if request_sdate and request_sdate > cached_latest:
269
281
  # 请求的开始日期晚于缓存的最晚日期,无重叠
270
- return None
282
+ has_overlap = False
271
283
 
272
- # 有重叠,返回缓存中可用的部分数据
273
- # 计算实际可用的日期范围
274
- actual_sdate = max(request_sdate, cached_earliest) if request_sdate and cached_earliest else (request_sdate or cached_earliest)
275
- actual_edate = min(request_edate, cached_latest) if request_edate and cached_latest else (request_edate or cached_latest)
284
+ if not has_overlap:
285
+ return None
276
286
 
277
- # 过滤数据
278
- filtered_df = self._filter_dataframe_by_date(
279
- df,
280
- actual_sdate.strftime('%Y-%m-%d') if actual_sdate else None,
281
- actual_edate.strftime('%Y-%m-%d') if actual_edate else None
282
- )
287
+ # 按照请求的日期范围过滤数据(即使缓存中有更多数据,也只返回请求范围内的)
288
+ # 重要:必须按照 edate 截取,和从网络获取的行为一致
289
+ filtered_df = self._filter_dataframe_by_date(df, sdate, edate)
283
290
 
284
291
  if filtered_df.empty:
285
292
  return None
286
293
 
287
- # 确保索引是 DatetimeIndex
288
- if not isinstance(filtered_df.index, pd.DatetimeIndex):
289
- try:
290
- filtered_df.index = pd.to_datetime(filtered_df.index)
291
- except (ValueError, TypeError):
292
- pass # 如果转换失败,保持原样
293
-
294
294
  return (symbol, name, filtered_df)
295
295
 
296
296
  def _get_pickle(self, base_key: str, symbol: str, sdate: str, edate: str,
@@ -311,47 +311,45 @@ class PersistentCache(Cache):
311
311
 
312
312
  df = cache_entry['data']
313
313
  name = cache_entry.get('name', '')
314
- earliest_date = cache_entry.get('earliest_date')
315
- latest_date = cache_entry.get('latest_date')
316
314
 
317
- # 获取缓存数据的日期范围
318
- cached_earliest = self._parse_date(earliest_date)
319
- cached_latest = self._parse_date(latest_date)
315
+ # 确保索引是 DatetimeIndex
316
+ if not isinstance(df.index, pd.DatetimeIndex):
317
+ try:
318
+ df.index = pd.to_datetime(df.index)
319
+ except (ValueError, TypeError):
320
+ return None
321
+
322
+ if df.empty:
323
+ return None
324
+
325
+ # 直接从 DataFrame 索引获取实际的日期范围
326
+ cached_earliest = df.index.min()
327
+ cached_latest = df.index.max()
320
328
 
321
- # 如果请求的日期范围完全在缓存范围内,直接返回过滤后的数据
329
+ # 解析请求的日期范围
322
330
  request_sdate = self._parse_date(sdate) if sdate else None
323
331
  request_edate = self._parse_date(edate) if edate else None
324
332
 
325
- # 检查是否有重叠
326
- if request_edate and cached_earliest and request_edate < cached_earliest:
333
+ # 检查是否有重叠:如果请求的日期范围与缓存数据有重叠,就返回过滤后的数据
334
+ # 注意:即使缓存中有部分数据,也应该返回(让上层决定是否需要扩展)
335
+ has_overlap = True
336
+ if request_edate and request_edate < cached_earliest:
327
337
  # 请求的结束日期早于缓存的最早日期,无重叠
328
- return None
329
- if request_sdate and cached_latest and request_sdate > cached_latest:
338
+ has_overlap = False
339
+ if request_sdate and request_sdate > cached_latest:
330
340
  # 请求的开始日期晚于缓存的最晚日期,无重叠
331
- return None
341
+ has_overlap = False
332
342
 
333
- # 有重叠,返回缓存中可用的部分数据
334
- # 计算实际可用的日期范围
335
- actual_sdate = max(request_sdate, cached_earliest) if request_sdate and cached_earliest else (request_sdate or cached_earliest)
336
- actual_edate = min(request_edate, cached_latest) if request_edate and cached_latest else (request_edate or cached_latest)
343
+ if not has_overlap:
344
+ return None
337
345
 
338
- # 过滤数据
339
- filtered_df = self._filter_dataframe_by_date(
340
- df,
341
- actual_sdate.strftime('%Y-%m-%d') if actual_sdate else None,
342
- actual_edate.strftime('%Y-%m-%d') if actual_edate else None
343
- )
346
+ # 按照请求的日期范围过滤数据(即使缓存中有更多数据,也只返回请求范围内的)
347
+ # 重要:必须按照 edate 截取,和从网络获取的行为一致
348
+ filtered_df = self._filter_dataframe_by_date(df, sdate, edate)
344
349
 
345
350
  if filtered_df.empty:
346
351
  return None
347
352
 
348
- # 确保索引是 DatetimeIndex
349
- if not isinstance(filtered_df.index, pd.DatetimeIndex):
350
- try:
351
- filtered_df.index = pd.to_datetime(filtered_df.index)
352
- except (ValueError, TypeError):
353
- pass # 如果转换失败,保持原样
354
-
355
353
  return (symbol, name, filtered_df)
356
354
 
357
355
  def put(self, key: str, value: Any, ttl: Optional[int] = None) -> None:
@@ -449,7 +447,10 @@ class PersistentCache(Cache):
449
447
  def _put_duckdb(self, base_key: str, symbol: str, name: str, df: pd.DataFrame,
450
448
  earliest_date: Optional[str], latest_date: Optional[str],
451
449
  freq: str, fq: str, expire_at: Optional[pd.Timestamp]):
452
- """存储到 duckdb"""
450
+ """存储到 duckdb
451
+
452
+ 注意:earliest_date 和 latest_date 仅用于记录,实际查询时从 DataFrame 索引获取
453
+ """
453
454
  import pickle
454
455
  data_blob = pickle.dumps(df)
455
456
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
5
5
  Requires-Python: >=3.9.0
6
6
  Description-Content-Type: text/markdown
@@ -18,7 +18,7 @@ Requires-Dist: duckdb>=0.9.0; extra == "persistent"
18
18
 
19
19
  ## 版本信息
20
20
 
21
- 当前版本:**0.4.1**
21
+ 当前版本:**0.4.2**
22
22
 
23
23
  ## 主要特性
24
24
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes