Skip to content

feat: split the sources in modules so it become very verbose the source of the database - #339

Open
luabida wants to merge 17 commits into
AlertaDengue:mainfrom
luabida:split-sources-verbose
Open

feat: split the sources in modules so it become very verbose the source of the database#339
luabida wants to merge 17 commits into
AlertaDengue:mainfrom
luabida:split-sources-verbose

Conversation

@luabida

@luabida luabida commented Aug 30, 2026

Copy link
Copy Markdown
Member

No description provided.

@codecov-commenter

codecov-commenter commented Aug 30, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.72169% with 180 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@c8fe5ff). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pysus/management/sync.py 50.92% 80 Missing ⚠️
pysus/api/_impl/source.py 77.71% 41 Missing ⚠️
pysus/api/_impl/databases.py 88.40% 16 Missing ⚠️
pysus/api/bag.py 87.15% 14 Missing ⚠️
pysus/management/records.py 76.31% 9 Missing ⚠️
pysus/api/ducklake/catalog/adapters.py 57.14% 6 Missing ⚠️
pysus/api/ducklake/models.py 42.85% 4 Missing ⚠️
pysus/api/ducklake/functional.py 25.00% 3 Missing ⚠️
pysus/api/types.py 57.14% 3 Missing ⚠️
pysus/tests/api/test_source.py 98.39% 3 Missing ⚠️
... and 1 more
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #339   +/-   ##
=======================================
  Coverage        ?   94.88%           
=======================================
  Files           ?      177           
  Lines           ?    21380           
  Branches        ?        0           
=======================================
  Hits            ?    20286           
  Misses          ?     1094           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@luabida
luabida force-pushed the split-sources-verbose branch from 325ad3c to 5ba7f3c Compare August 31, 2026 12:05
luabida added 12 commits August 31, 2026 09:13
- Lead all docs (README, quickstart, data-sources, api, tutorials,
  migration, guides) with the origin-namespaced API
- Add flat -> namespaced migration guide with deprecation warning text
- Re-execute getting_started_pysus.ipynb with pysus.ftp.sinasc(...)
- info_table()/search() now show per-origin fetch hints (pysus.ftp.sinan)
  that only appear when a real namespaced fetcher exists
- Add tests for the new info() call-hint column
Saude (dadosabertos.saude.gov.br) resources are frequently Latin-1 even
when advertised as UTF-8. pd.read_csv assumed UTF-8, so every resource
failed to parse and _fetch_saude returned an empty DataFrame for any
as_dataframe=True call (both flat pysus.arboviroses and the namespaced
pysus.saude.arboviroses).

Extract _saude_csv_to_frame() helper that sniffs the delimiter and falls
back across encodings, and add regression tests covering UTF-8, Latin-1,
and corrupt inputs.
Add a download parameter (default True) threaded through fetch(),
_fetch_catalog(), _fetch_origin_direct(), _fetch_ducklake() and
_fetch_saude(). When download=False each fetcher resolves which files
would be fetched and returns their remote paths (or Saude CSV resource
URLs) without downloading anything. as_dataframe is ignored in that
case because there is no local data to build a DataFrame from.

Also fetch each Saude CKAN package exactly once, sharing the resolved
CSV resources between listing and downloading.

Ignore roadmap markdown files via the lowercase roadmap*.md pattern.
Namespaced fetchers (pysus.ftp.*, pysus.dadosgov.*, pysus.saude.*) now
return a high-level, synchronous FileBag instead of a raw list of paths:

- download=False -> remote FileBag of BaseRemoteFile entities (reports
  "(remote)" in repr; as_dataframe ignored), with _RemoteURL stand-ins
  for URL-only origins such as Saude.
- download=True + as_dataframe=False -> local FileBag of downloaded files.
- as_dataframe=True -> unchanged concatenated DataFrame.

FileBag supports len/iter/getitem (incl. slice), paths/kind/first,
download()/download_one(), and to_dataframe()/df. The flat, deprecated
fetchers keep their historic list[str] | pd.DataFrame return type.

Thread a private _bag flag through fetch -> _fetch_catalog /
_fetch_origin_direct / _fetch_ducklake / _fetch_saude, and coerce the
result via _coerce_bag. 14 new tests plus 2 updated origin tests;
docs updated to describe the new return type.
DuckDataset and File inherited Pydantic's default repr, which dumped every
field including private internals (e.g. border=<DatasetAdapter object>).
Add concise __repr__ implementations that surface the meaningful fields:
DuckDataset shows its record name; File shows path, type, optional group,
and dataset. No serialization behavior changes.
Add a full walkthrough of the origin-namespaced FileBag workflow
(list with download=False, inspect, download/download_one, to_dataframe)
to tutorials.rst, with an explicit anchor target; reference it from
data-sources.rst and files-and-formats.rst so all guides show the
download=False -> FileBag -> download() -> to_dataframe() path rather
than only the DataFrame form.
info() now prints a footer tip reminding users that namespaced fetchers
return a FileBag, accept download=False to list files without fetching,
and as_dataframe=True for a DataFrame. Add the same guidance to the
info_table docstring.
Saude's CNES was declared in the catalog (DatasetSpec) but had no
namespaced fetcher, so pysus.info() showed an empty Call for it. Unlike
the FTP/DadosGov cnes (monthly state/year/month dumps), Saude serves CNES
as CKAN resources (/cnes/estabelecimentos, /cnes/tipounidades) through
_fetch_saude.

- Add saude_cnes() in _impl.databases: a **kwargs fetcher routing to
  _fetch_data(dataset="cnes", origin="Saude").
- Add a per-origin function alias map in _impl.source so build_origin_module
  binds SAUDE's "cnes" to saude_cnes while FTP/DadosGov keep the shared
  monthly-dump cnes.
- Register "cnes" in APPLICABILITY["SAUDE"]; update saude module docstring
  (19 themes) with the new fetcher.
- Tests: saude.cnes routes to _fetch_saude and returns a remote FileBag on
  download=False; info() now shows pysus.saude.cnes(...) (no dataset lacks a
  hint, so the omission test now exercises _fetcher_hint directly).

Full suite: 1626 passed, 2 skipped.
Replace the hard-coded _SAUDE_GROUP_MAP resolution in _fetch_saude with
spec-driven enumeration (DatasetSpec ckan_group + slug_patterns) so
slug-only themes like CNES, SISVAN and OUTROSTEMAS resolve correctly
instead of returning nothing.

Filter CSV resources by the format metadata (capturing *_csv.zip
multi-format archives) rather than by a bare .csv URL suffix, and unwrap
downloaded zips when building a DataFrame.
@luabida
luabida force-pushed the split-sources-verbose branch from 99a2152 to fe51573 Compare August 31, 2026 18:50
@luabida
luabida marked this pull request as ready for review August 31, 2026 18:53
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.

2 participants