|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +Guidance for working in this repository (`tidyfinance`, the Python companion |
| 4 | +package to the *Tidy Finance with Python* book). |
| 5 | + |
| 6 | +## Project layout |
| 7 | + |
| 8 | +- `tidyfinance/` — the package. |
| 9 | + - `__init__.py` — builds the public API automatically by scanning the |
| 10 | + public submodules and re-exporting their functions/classes (see |
| 11 | + `__all__`). Data-bearing functions are wrapped at this boundary by |
| 12 | + `backend._use_backend` so they honor the active polars/pandas backend. |
| 13 | + Keep this file's namespace clean: discovery loop variables, imports |
| 14 | + (`importlib`, `pkgutil`, `types`), and internal toggles are deleted or |
| 15 | + underscore-prefixed at the end so they don't leak into `dir(tidyfinance)` |
| 16 | + or the docs. |
| 17 | + - `core.py` — analytics functions (portfolio sorts, breakpoints, beta / |
| 18 | + Fama-MacBeth estimation, lagging, summary statistics). |
| 19 | + - `data_download.py` — `download_data` and the WRDS / Fama-French / FRED / |
| 20 | + OSAP / Hugging Face download helpers. |
| 21 | + - `backend.py` — `set_backend` / `get_backend` and the internal |
| 22 | + `_use_backend` decorator (private — must stay underscore-prefixed so it |
| 23 | + is not re-exported or documented). |
| 24 | + - `utilities.py`, `supported_datasets.py` — helpers and dataset metadata. |
| 25 | + - `_internal.py`, `_pseudo.py` — private modules (leading underscore = |
| 26 | + not scanned for the public API). |
| 27 | + |
| 28 | +## Conventions |
| 29 | + |
| 30 | +### Docstrings |
| 31 | + |
| 32 | +- NumPy-style docstrings, parsed by Great Docs (griffe, `parser: numpy`). |
| 33 | +- **Examples must use fenced ` ```python ` code blocks, NOT doctest `>>>` / |
| 34 | + `...` prompts.** The Great Docs copy button copies code verbatim, and |
| 35 | + prompts make examples impossible to paste and run. Write: |
| 36 | + |
| 37 | + ```` |
| 38 | + Examples |
| 39 | + -------- |
| 40 | + ```python |
| 41 | + import numpy as np |
| 42 | + from tidyfinance import winsorize |
| 43 | + data = np.random.default_rng(123).standard_normal(100) |
| 44 | + winsorized = winsorize(data, 0.05) |
| 45 | + ``` |
| 46 | + ```` |
| 47 | + |
| 48 | + Do not reintroduce `>>>` examples. If you ever need verifiable doctests |
| 49 | + with expected output, raise it as a deliberate change — the current |
| 50 | + examples are input-only and carry no doctest assertions. |
| 51 | + |
| 52 | +### Public API |
| 53 | + |
| 54 | +- A function is part of the public API by living in a public (non-`_`) |
| 55 | + submodule as a function/class defined within the package — it is then |
| 56 | + auto-discovered and re-exported from `tidyfinance`. |
| 57 | +- To keep something out of the public API and the Reference page, prefix it |
| 58 | + with `_` (module or name). |
| 59 | +- Do not name a module `core`, `utils`, `helpers`, `constants`, `config`, or |
| 60 | + `settings` and expect it to appear in the docs: Great Docs auto-excludes |
| 61 | + those names. `core` is kept only because `great-docs.yml` lists it under |
| 62 | + `auto_include`. |
| 63 | + |
| 64 | +### Style |
| 65 | + |
| 66 | +- Ruff, `line-length = 80` (`[tool.ruff]` in `pyproject.toml`). Keep code |
| 67 | + and docstrings within 80 columns. |
| 68 | + |
| 69 | +## Common commands |
| 70 | + |
| 71 | +This project uses `uv`. |
| 72 | + |
| 73 | +```bash |
| 74 | +uv run pytest # run the test suite (tests/test_*.py) |
| 75 | +uv run pytest tests/test_core.py |
| 76 | +uv run ruff check . # lint |
| 77 | +uv run ruff format . # format |
| 78 | +``` |
| 79 | + |
| 80 | +Every public function should have a matching `tests/test_<name>.py`. |
| 81 | + |
| 82 | +## Documentation (Great Docs) |
| 83 | + |
| 84 | +- Config: `great-docs.yml`. Generated output lives in `great-docs/` |
| 85 | + (git-ignored build artifacts). |
| 86 | + |
| 87 | +```bash |
| 88 | +uv run great-docs build # build the site |
| 89 | +uv run great-docs preview --port 3000 # local preview (auto-rebuilds) |
| 90 | +uv run great-docs scan # preview what will be discovered as public API |
| 91 | +``` |
| 92 | + |
| 93 | +- The navbar version badge comes from the latest **GitHub Release**, not |
| 94 | + `pyproject.toml` — there is no option to read it from `pyproject.toml`. |
| 95 | + Publish a release to update it. |
0 commit comments