Make financepy an optional import in abstractvolsurface - #80
Open
propcgamer20-png wants to merge 1 commit into
Open
propcgamer20-png wants to merge 1 commit into
propcgamer20-png wants to merge 1 commit into
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per #60 ("This should be optional.").
src/finmarketpy/curve/volatility/abstractvolsurface.pyhad an unguarded module-levelfrom financepy.utils.date import Date, soimport AbstractVolSurface(and thereforeFXVolSurface, which subclasses it) requiredfinancepy- even thoughDateis used in a single helper,_findate().fxvolsurface.pyandfxoptionspricer.pyalready wrap theirfinancepyimports intry/except; the base class did not.Change
and
_findate()raises a clearImportError(pointing atpip install financepy) if it is called withoutfinancepy. 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-existingE402ruff finding on that line (ruff checkon the file: 1 finding before, 0 after).Verified: the module loads with
financepyabsent (Date is None).Closes #60