diff --git a/CHANGELOG.md b/CHANGELOG.md index 687c157..019724e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,11 @@ parser tuned to their template family. page 8, dropping holdings sections that landed on pages 4-7. - **CDSL MF holdings** rows with `DIRECT` (or any non-`ARN-XXXX` distribution-mode token) now correctly populate `pnl` and `return_`. +- **Leading-dot decimals** (`.196`, `-.5`) are now recognised as + numeric by the NSDL / CDSL cell classifier. CDSL occasionally + drops the leading zero on sub-unit balances; under the old regex + those cells were mis-bucketed as text, shifting the row layout + and producing a silent `Σholdings ≠ balance` mismatch. ## 0.9.0 - 2026-05-22 - Add support for CDSL statements diff --git a/casparser/parsers/cdsl.py b/casparser/parsers/cdsl.py index 2ce58e8..0b82d30 100644 --- a/casparser/parsers/cdsl.py +++ b/casparser/parsers/cdsl.py @@ -55,7 +55,10 @@ from .pageobj import Block ISIN_RE = re.compile(r"^[A-Z]{2}[0-9A-Z]{9}\d$") INF_ISIN_RE = re.compile(r"^INF[0-9A-Z]{8}\d$") INE_ISIN_RE = re.compile(r"^IN[E9][0-9A-Z]{8}\d$") -NUMERIC_RE = re.compile(r"^-?[\d,]+(?:\.\d+)?$") +# CDSL sometimes drops the leading zero on fractional values (e.g. a +# `0.196` unit balance prints as `.196`), so the integer part is +# optional when a decimal part is present. +NUMERIC_RE = re.compile(r"^-?(?:[\d,]+(?:\.\d+)?|\.\d+)$") PERIOD_RE = re.compile( r"(?:for\s+the\s+period\s+from|statement\s+for\s+the\s+period\s+from)\s+" diff --git a/casparser/parsers/nsdl.py b/casparser/parsers/nsdl.py index aa123b2..25707b7 100644 --- a/casparser/parsers/nsdl.py +++ b/casparser/parsers/nsdl.py @@ -56,7 +56,10 @@ from .pageobj import Block, Cell ISIN_RE = re.compile(r"^[A-Z]{2}[0-9A-Z]{9}\d$") INF_ISIN_RE = re.compile(r"^INF[0-9A-Z]{8}\d$") INE_ISIN_RE = re.compile(r"^IN[E9][0-9A-Z]{8}\d$") -NUMERIC_RE = re.compile(r"^-?[\d,]+(?:\.\d+)?$") +# Some templates drop the leading zero on fractional values (e.g. a +# `0.196` unit balance prints as `.196`), so the integer part is +# optional when a decimal part is present. +NUMERIC_RE = re.compile(r"^-?(?:[\d,]+(?:\.\d+)?|\.\d+)$") PERIOD_RE = re.compile( r"(?:for\s+the\s+period\s+from|statement\s+for\s+the\s+period\s+from)\s+"