Skip to content

Make financepy an optional import in abstractvolsurface - #80

Open
propcgamer20-png wants to merge 1 commit into
cuemacro:masterfrom
propcgamer20-png:optional-financepy
Open

propcgamer20-png wants to merge 1 commit into
cuemacro:masterfrom
propcgamer20-png:optional-financepy

Conversation

@propcgamer20-png

Copy link
Copy Markdown

Per #60 ("This should be optional.").

src/finmarketpy/curve/volatility/abstractvolsurface.py had an unguarded module-level from financepy.utils.date import Date, so import AbstractVolSurface (and therefore FXVolSurface, which subclasses it) required financepy - even though Date is used in a single helper, _findate(). fxvolsurface.py and fxoptionspricer.py already wrap their financepy imports in try/except; the base class did not.

Change

try:
    from financepy.utils.date import Date
except ImportError:  # financepy is an optional dependency (FX options pricing)
    Date = None

and _findate() raises a clear ImportError (pointing at pip install financepy) if it is called without financepy. The rest of the module (_extremes, extract_vol_surface_across_dates) is plain numpy/pandas and now imports without it.

Also moves the import above the module-level ABC = abc.ABCMeta(...) statement, fixing the pre-existing E402 ruff finding on that line (ruff check on the file: 1 finding before, 0 after).

Verified: the module loads with financepy absent (Date is None).

Closes #60

`src/finmarketpy/curve/volatility/abstractvolsurface.py` imported
`from financepy.utils.date import Date` at module level, so importing
`AbstractVolSurface` (and its subclass `FXVolSurface`) required financepy
even though `Date` is used in exactly one helper, `_findate()`.
`fxvolsurface.py` and `fxoptionspricer.py` already guard their financepy
imports; this brings the base class in line.

The import is now wrapped in try/except ImportError with a `None`
fallback, and `_findate()` raises a clear ImportError (pointing at
`pip install financepy`) if it is actually called without financepy
installed. Everything else in the module is plain numpy/pandas and now
imports fine without it. Also fixes the pre-existing E402 (the import was
below a module-level statement).

Closes cuemacro#60
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.

financepy missing

1 participant