Flatten analytics/ subpackage to top-level jquantstats/#439
Merged
Conversation
Co-authored-by: tschm <2046079+tschm@users.noreply.github.com> Agent-Logs-Url: https://github.com/tschm/jquantstats/sessions/fd5ca62f-558f-413c-9270-959a2f65d836
Copilot
AI
changed the title
[WIP] Flatten analytics subpackage to top level
Flatten Mar 23, 2026
analytics/ subpackage to top-level jquantstats/
Fix stale import in analytics_demo.py (jquantstats.analytics no longer exists after subpackage flattening) and bump marimo pin to 0.20.4 in both notebooks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Portfolioand its supporting modules were buried in ananalytics/subpackage, making the import hierarchy unnecessarily deep. This flattens everything tosrc/jquantstats/.File moves
analytics/portfolio.pyportfolio.pyanalytics/_portfolio_data.py_portfolio_data.pyanalytics/_cost_model.py_cost_model.pyanalytics/_plots.py_portfolio_plots.py(renamed — avoids clash with existing top-level_plots.py)analytics/_report.py_report.pyanalytics/exceptions.pyexceptions.pyanalytics/templates/templates/analytics/__init__.pyand theanalytics/directory are deleted entirely.Import changes
portfolio.py:from .._data/from .._stats→from ._data/from ._stats;from ._plots import Plots→from ._portfolio_plots import Plots; deferred inline import updated likewise__init__.py:from .analytics import CostModel/Portfolio→from ._cost_model import CostModel/from .portfolio import Portfolioexceptions.py: doctests updated fromjquantstats.analytics.exceptions.*→jquantstats.exceptions.*test_analytics/:from jquantstats.analytics import …→from jquantstats import …Public API — unchanged
Original prompt
Goal
Flatten the
analytics/subpackage so that the two core classes —PortfolioandPortfolioData— live at the top level of the package (src/jquantstats/), alongside the existing_data.py,_stats.py, etc. The supporting helpers (_plots.py,_report.py,_cost_model.py,exceptions.py) should also move up and lose theiranalytics.prefix.Current structure
Target structure
The
analytics/directory should be deleted entirely after the move.Required import updates
All files must have their
from .analytics.X/from ..X/from .Ximports updated to reflect the new flat layout. Specifically:portfolio.py(wasanalytics/portfolio.py)from ._cost_model import CostModel(wasfrom ._cost_model import CostModel— same relative name, just now at top level)from ._portfolio_plots import Plots(wasfrom ._plots import Plots)from ._portfolio_data import PortfolioData(wasfrom ._portfolio_data import PortfolioData)from ._report import Report(wasfrom ._report import Report)from .exceptions import IntegerIndexBoundError(wasfrom .exceptions import ...)from ._data import Data,from ._stats import Stats(werefrom .._data import Data,from .._stats import Stats)_portfolio_data.py(wasanalytics/_portfolio_data.py)from .exceptions import (...)(wasfrom .exceptions import ...— same relative name, now top level)_portfolio_plots.py(wasanalytics/_plots.py)from .portfolio import Portfolioin theTYPE_CHECKINGblock (wasfrom .portfolio import Portfolio— same relative name)_report.py(wasanalytics/_report.py)from .portfolio import Portfolioin theTYPE_CHECKINGblock (wasfrom .portfolio import Portfolio)_TEMPLATES_DIR = Path(__file__).parent / "templates"(was the same, now correctly points tosrc/jquantstats/templates/)src/jquantstats/__init__.pyfrom .analytics import CostModel as CostModel→from ._cost_model import CostModel as CostModelfrom .analytics import Portfolio as Portfolio→from .portfolio import Portfolio as Portfolioexceptions.py(wasanalytics/exceptions.py)jquantstats.analytics.exceptions.MissingDateColumnError— update tojquantstats.exceptions.MissingDateColumnErrorNotes
_plots.pyis forData/Statsplots and is unrelated toanalytics/_plots.py(which is thePlotsfacade forPortfolio). To avoid the name clash, renameanalytics/_plots.py→_portfolio_plots.py.templates/directory must be moved tosrc/jquantstats/templates/; the_TEMPLATES_DIRpath in_report.pyalready usesPath(__file__).parent / "templates", so it will automatically resolve correctly once the file is at the top level.analytics/__init__.pyshould be deleted (it only re-exportedCostModelandPortfolio, which are now directly importable).from jquantstats import Portfolioandfrom jquantstats import CostModelmust continue to work (they are re-exported fromsrc/jquantstats/__init__.py). The subpackage pathfrom jquantstats.analytics import Portfoliocan be dropped.jquantstats.analytics.*paths to reflect the new flat paths.jquantstats.analytics.*and update them too.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: I think t...
This pull request was created from Copilot chat.
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.