lixinger-python 0.3.27__py3-none-any.whl → 0.3.28__py3-none-any.whl

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.
@@ -1,5 +1,6 @@
1
1
  """国内各类债券数据模型."""
2
2
 
3
+ from pandera.engines.pandas_engine import DateTime
3
4
  import pandera.pandas as pa
4
5
 
5
6
 
@@ -14,7 +15,7 @@ class DomesticDebtSecurities(pa.DataFrameModel):
14
15
  class Config:
15
16
  """Pandera configuration."""
16
17
 
17
- coerce = True
18
+ coerce = False
18
19
  strict = False # Allow extra metrics columns like y.gs_i.t
19
20
 
20
- date: pa.typing.Series[pa.typing.DateTime]
21
+ date: pa.typing.Series[DateTime] = pa.Field(dtype_kwargs={"time_zone_agnostic": True})
@@ -1,5 +1,6 @@
1
1
  """官方储备资产数据模型."""
2
2
 
3
+ from pandera.engines.pandas_engine import DateTime
3
4
  import pandera.pandas as pa
4
5
 
5
6
 
@@ -14,7 +15,7 @@ class OfficialReserveAssets(pa.DataFrameModel):
14
15
  class Config:
15
16
  """Pandera configuration."""
16
17
 
17
- coerce = True
18
+ coerce = False
18
19
  strict = False # Allow extra metrics columns like y.ora.t
19
20
 
20
- date: pa.typing.Series[pa.typing.DateTime]
21
+ date: pa.typing.Series[DateTime] = pa.Field(dtype_kwargs={"time_zone_agnostic": True})
@@ -1,5 +1,6 @@
1
1
  """人民币存款数据模型."""
2
2
 
3
+ from pandera.engines.pandas_engine import DateTime
3
4
  import pandera.pandas as pa
4
5
 
5
6
 
@@ -14,7 +15,7 @@ class RmbDeposits(pa.DataFrameModel):
14
15
  class Config:
15
16
  """Pandera configuration."""
16
17
 
17
- coerce = True
18
+ coerce = False
18
19
  strict = False # Allow extra metrics columns like y.rmb_d.t
19
20
 
20
- date: pa.typing.Series[pa.typing.DateTime]
21
+ date: pa.typing.Series[DateTime] = pa.Field(dtype_kwargs={"time_zone_agnostic": True})
@@ -1,5 +1,6 @@
1
1
  """人民币贷款数据模型."""
2
2
 
3
+ from pandera.engines.pandas_engine import DateTime
3
4
  import pandera.pandas as pa
4
5
 
5
6
 
@@ -14,7 +15,7 @@ class RmbLoans(pa.DataFrameModel):
14
15
  class Config:
15
16
  """Pandera configuration."""
16
17
 
17
- coerce = True
18
+ coerce = False
18
19
  strict = False # Allow extra metrics columns like y.rmb_l.t
19
20
 
20
- date: pa.typing.Series[pa.typing.DateTime]
21
+ date: pa.typing.Series[DateTime] = pa.Field(dtype_kwargs={"time_zone_agnostic": True})
@@ -1,5 +1,6 @@
1
1
  """社会融资规模数据模型."""
2
2
 
3
+ from pandera.engines.pandas_engine import DateTime
3
4
  import pandera.pandas as pa
4
5
 
5
6
 
@@ -14,7 +15,7 @@ class SocialFinancing(pa.DataFrameModel):
14
15
  class Config:
15
16
  """Pandera configuration."""
16
17
 
17
- coerce = True
18
+ coerce = False
18
19
  strict = False # Allow extra metrics columns like y.sf.t
19
20
 
20
- date: pa.typing.Series[pa.typing.DateTime]
21
+ date: pa.typing.Series[DateTime] = pa.Field(dtype_kwargs={"time_zone_agnostic": True})
@@ -11,7 +11,11 @@ def camel_to_snake(name: str) -> str:
11
11
 
12
12
 
13
13
  def get_response_df(data: Any, model: type[pa.DataFrameModel]) -> pd.DataFrame:
14
- """Convert API response data to a validated pandas DataFrame."""
14
+ """Convert API data to a validated DataFrame.
15
+
16
+ Timezone-agnostic schema fields preserve input offsets. Their date-only and
17
+ naive values are localized to Asia/Shanghai. Mixed offsets use object dtype.
18
+ """
15
19
  if not data:
16
20
  return pd.DataFrame()
17
21
 
@@ -42,16 +46,27 @@ def get_response_df(data: Any, model: type[pa.DataFrameModel]) -> pd.DataFrame:
42
46
  if "p_c_benchmark" in df.columns:
43
47
  df["p_c_benchmark"] = df["p_c_benchmark"].apply(lambda x: ",".join(x) if isinstance(x, list) else x)
44
48
 
45
- # Handle datetime columns to support mixed timezones by taking the face time
49
+ # Timezone-aware parsing is enabled only by the response field's schema.
46
50
  schema = model.to_schema()
47
51
  for col_name, col in schema.columns.items():
48
52
  if (
49
- "datetime" in str(col.dtype).lower()
50
- and col_name in df.columns
51
- and not pd.api.types.is_datetime64_any_dtype(df[col_name])
52
- ):
53
- # Extract face time to avoid mixed timezone issues (e.g. historical DST)
54
- df[col_name] = pd.to_datetime(df[col_name].astype(str).str.slice(0, 19), errors="coerce")
53
+ "datetime" in str(col.dtype).lower() or getattr(col.dtype, "time_zone_agnostic", False)
54
+ ) and col_name in df.columns:
55
+ if getattr(col.dtype, "time_zone_agnostic", False):
56
+ df[col_name] = df[col_name].map(_with_timezone)
57
+ elif not pd.api.types.is_datetime64_any_dtype(df[col_name]):
58
+ # Legacy schemas retain their existing face-time behavior.
59
+ df[col_name] = pd.to_datetime(df[col_name].astype(str).str.slice(0, 19), errors="coerce")
55
60
 
56
61
  # Validate the DataFrame using the pandera model
57
62
  return model.validate(df)
63
+
64
+
65
+ def _with_timezone(value: Any) -> Any:
66
+ """Preserve explicit offsets; interpret naive values as Beijing time."""
67
+ timestamp = pd.to_datetime(value, errors="coerce")
68
+ if pd.isna(timestamp):
69
+ return pd.NaT
70
+ if timestamp.tzinfo is None:
71
+ timestamp = timestamp.tz_localize("Asia/Shanghai")
72
+ return timestamp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lixinger-python
3
- Version: 0.3.27
3
+ Version: 0.3.28
4
4
  Summary: Python SDK for Lixinger Financial Data API
5
5
  Project-URL: Homepage, https://www.lixinger.com
6
6
  Project-URL: Documentation, https://www.lixinger.com/open/api/doc
@@ -146,24 +146,24 @@ lixinger/models/cn/industry/margin_trading/sw.py,sha256=GyBhpZxSm1aoQHdzJvjb5INp
146
146
  lixinger/models/cn/industry/margin_trading/sw_2021.py,sha256=JWdEVXarlKso3JOpMJ7zvkw-I5tsLlXagJFXEJxYC3s,1399
147
147
  lixinger/models/macro/__init__.py,sha256=2JzNqBA9489NH8kQn33o7vcVkW4p12BbggZT215P89Y,826
148
148
  lixinger/models/macro/crude_oil.py,sha256=hvve8HL3FF3V1iOIE5shH7SUHyssj3f-vjIsZAY-KoQ,574
149
- lixinger/models/macro/domestic_debt_securities.py,sha256=xCzD5GfM5iJFED7oViq9UvvtxsCdu7sV00svuY_Vuj4,601
149
+ lixinger/models/macro/domestic_debt_securities.py,sha256=ch_TvQpWgUZ4jpgxrQE6EvsbNa8d9hXmAMjz8pgN_k8,697
150
150
  lixinger/models/macro/gold_price.py,sha256=nqsfQWG2zH6dZ7LIu616dZI4xmEKzkHCrTv0hTgLmk0,571
151
151
  lixinger/models/macro/national_debt.py,sha256=EVOCgzoahjKW0YMq-08ICw17GpOmhJdBWQGqmO0oqQc,581
152
152
  lixinger/models/macro/natural_gas.py,sha256=kAGDY9ZqRrm96azBvjLmk8IyZz5_DhEHfUWR1HrXeM0,554
153
153
  lixinger/models/macro/non_ferrous_metals.py,sha256=8fuOfmR7So1mWZtUuOBO9UiQEN58u1qrEbh6exJ5Vq0,636
154
- lixinger/models/macro/official_reserve_assets.py,sha256=eDaifzFKo4CKZxel6yIfvE6jdYGRBNiIB51b7fLCC2A,598
154
+ lixinger/models/macro/official_reserve_assets.py,sha256=Zk_0D6jrLU4erV5-OzgICg8e34AdC80mcJPhisi1LMc,694
155
155
  lixinger/models/macro/platinum_price.py,sha256=4nh11VoHfnL_cUGUeNr0I1njaF4ovmISnKE9_Az16RA,538
156
- lixinger/models/macro/rmb_deposits.py,sha256=SeJoD0t3xHjNuSUX6BCUi343wQCnRgOs93BIW9bE9ss,583
157
- lixinger/models/macro/rmb_loans.py,sha256=Mptmogd_R2e8TGYkJ36QMtIyLzxmJJdKxt7eJryX3nQ,580
156
+ lixinger/models/macro/rmb_deposits.py,sha256=KzvkxIDzZPNAHXKWSCDc9-GvZfXL-9mZQONnaVWx338,679
157
+ lixinger/models/macro/rmb_loans.py,sha256=36CHRPt8QRvkadxAa0VlqKCYo9i8jMdUTGFWaf_sBfg,676
158
158
  lixinger/models/macro/silver_price.py,sha256=8OPmXoA_aK-J6VkZpDI9qsH19gbZrzpnMi68afqRFeI,536
159
- lixinger/models/macro/social_financing.py,sha256=OIV1v_D0eW2y8wvVwG5lV8AspYv6QyxrQJlTUskQUa0,590
159
+ lixinger/models/macro/social_financing.py,sha256=07O1cTuuj7RoV8aY0ja-Pb2yVW-mIehujlkvkssH3C4,686
160
160
  lixinger/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
161
161
  lixinger/utils/api.py,sha256=BktR40JtKCMe9excFWo4ujsq3GiQK4ypJLG3MpJgo2s,402
162
- lixinger/utils/dataframe.py,sha256=tYBrNdmJ4poyuwD-9XgzHt3A_A8bBo0cdHiu8Yy9e9A,2208
162
+ lixinger/utils/dataframe.py,sha256=9i9J_hWQoUqAczsbEC7T5iZOdZmZddkKqrbBuRc19UM,2853
163
163
  lixinger/utils/dict.py,sha256=yvbUtv8QpRmy0d_o_7gCuEwwiEfBji5_xB490ANxilw,589
164
164
  lixinger/utils/rate_limiter.py,sha256=ZHlRTTL60L62uRA_f--LD26qkAfk-pHBllRqPapAXQM,1141
165
165
  lixinger/utils/retry.py,sha256=C9QBcrpD7WYAuT8R4SJfWNUZFj1mZsv-qyTRIFQDmwc,2862
166
- lixinger_python-0.3.27.dist-info/METADATA,sha256=XgAQa96f_t6LuQrTRjEHh_LSNn4pJA250F8q6m_zoAk,9207
167
- lixinger_python-0.3.27.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
168
- lixinger_python-0.3.27.dist-info/licenses/LICENSE,sha256=5oOwRq1lHSOScbNGCHr2feuNnhNYdGcArj6fSUfsC5U,1064
169
- lixinger_python-0.3.27.dist-info/RECORD,,
166
+ lixinger_python-0.3.28.dist-info/METADATA,sha256=RzzrcEO9_bi69d0C6gNiZzE8R4tAc1QB7ybS_mPkUD8,9207
167
+ lixinger_python-0.3.28.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
168
+ lixinger_python-0.3.28.dist-info/licenses/LICENSE,sha256=5oOwRq1lHSOScbNGCHr2feuNnhNYdGcArj6fSUfsC5U,1064
169
+ lixinger_python-0.3.28.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any