Skip to content

fix: import crash on narwhals 1.x; bump to 0.3.5 - #13

Closed
jrosenfeld13 wants to merge 1 commit into
mainfrom
fix/narwhals-1x-import
Closed

fix: import crash on narwhals 1.x; bump to 0.3.5#13
jrosenfeld13 wants to merge 1 commit into
mainfrom
fix/narwhals-1x-import

Conversation

@jrosenfeld13

Copy link
Copy Markdown
Contributor

Problem

import centimators crashes with TypeError: unsupported operand type(s) for |: 'str' and 'NoneType' on any narwhals 1.x install (the declared floor is >=1.39.0). narwhals 1.x exposes narwhals.typing aliases like IntoSeries as plain strings at runtime, so era_series: IntoSeries | None = None in neutralization.py (eagerly imported at top level) and penalization.py explodes at import time.

CI never caught it because the lockfile tracks latest narwhals (2.10.2), where the aliases are real types.

Fix

  • from __future__ import annotations in neutralization.py and penalization.py (annotations become lazy strings on every Python/narwhals version).
  • tests/test_imports.py: pkgutil walk importing every module — ImportError (optional deps) tolerated, anything else fails.
  • New CI job running the import test with --with "narwhals==1.39.0" so the floor is actually exercised.
  • Version 0.3.4 → 0.3.5.

Verified

  • Full suite: 52 passed, 4 skipped on locked narwhals 2.10.2.
  • Import smoke test green on narwhals 1.39.0 (floor) and 1.48.0.
  • LogReturn→Rank→MovingAverage→Lag chain on narwhals 1.48.0: bit-exact vs pinned 0.3.2 semantics (max abs diff 0.0 across 80 feature columns, 32.5k-row panel).

🤖 Generated with Claude Code

https://claude.ai/code/session_01B1GweKDrBJLe7KcqhmZSPm

narwhals 1.x exposes narwhals.typing aliases (IntoSeries) as plain strings
at runtime, so `IntoSeries | None` in neutralization/penalization signatures
raised TypeError at import time — and neutralization is eagerly imported, so
`import centimators` itself crashed on any narwhals 1.x install (the declared
floor is 1.39). Add `from __future__ import annotations` to both modules,
an import-walk smoke test, and a CI job running it at the narwhals floor so
the latest-narwhals lockfile can't mask floor breakage again.

Verified: full suite green on locked narwhals 2.10.2; import test green on
1.39.0; four-transformer chain bit-exact vs pinned reference on 1.48.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1GweKDrBJLe7KcqhmZSPm
@cursor

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@jrosenfeld13
jrosenfeld13 deleted the fix/narwhals-1x-import branch July 23, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant