Skip to content

fix: quiet default logging for notebook/API use; sharpen actionable notices - #40

Open
micahpw wants to merge 1 commit into
mainfrom
fix/notebook-logging-and-warnings
Open

fix: quiet default logging for notebook/API use; sharpen actionable notices#40
micahpw wants to merge 1 commit into
mainfrom
fix/notebook-logging-and-warnings

Conversation

@micahpw

@micahpw micahpw commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Closes the remaining part of #22 (the "unsolicited DEBUG log spam on plain import" section) plus two related notebook-usability gaps surfaced while scoping it.

Background

#22 already got most of its fixes earlier (lazy scenariohandlers imports, dropping the quickplots/matplotlib import from plexos.py, de-blanketed datahelpers). The one remaining piece: a plain import gat inherits loguru's untouched default sink, which -- verified, not assumed -- shows every DEBUG-level call across the codebase (~90 call sites), not just the plot-function registration spam originally reported.

Changes

  1. src/gat/__init__.py -- on first import, if loguru is still at its pristine single-handler state (len(handlers) == 1 and 0 in handlers), set the same quiet default the CLI already uses for itself (level="WARNING", mirroring setup_cli_logging). Never touches an already-configured sink. warnings.warn(...) -- the channel GAT already uses for actionable notices -- is untouched either way.
  2. src/gat/models/scenario.py -- the "no fuzzy match, assigning random color" warning didn't explain how to fix it, unlike its sibling fuzzy-match warning right above it. Now it does (points at the technology_mappings config override).
  3. src/gat/scenariohandlers/multi.py -- MultiScenario._concat_gat_df silently unioned differing scenario timestamp indexes via pd.concat(axis=1), introducing NaN rows with zero signal when scenarios cover different date ranges/resolutions. Now warns, naming each scenario's actual range.

Why not just logger.disable("gat") / logger.remove()

Both considered and rejected:

  • logger.remove() at import is destructive -- loguru's logger is a single global singleton per process, so it would silently wipe out a sink a notebook user (or another library) already configured before importing gat. Reproduced this directly.
  • logger.disable("gat") would also silence the ~90 logger.warning/logger.error calls throughout loader.py, simulations/, backends/, discovery.py -- many carry real operational signal (parse failures, fallback behavior), not CLI-only noise. Blanket-disabling those seemed like the wrong tradeoff.

Verification

Ran in subprocesses / fresh interpreters, not just reasoned about:

  • import gat; import gat.quickplots.dispatch -- no DEBUG in output (was 3 lines before)
  • logger.warning(...) after import gat -- still visible
  • A sink added before import gat -- still receives messages after
  • CLI's own setup_cli_logging() -- still overrides normally
  • warnings.warn(...) -- unaffected either way
  • Synthetic MultiScenario with offset date ranges -- warns with both scenarios' actual ranges; matching ranges -- silent; get_generation_capacity (not time-series) -- never checked

New tests: tests/test_logging_defaults.py (subprocess-based, since the behavior only fires on a package's first import), tests/handlers/test_multiscenario_time_alignment.py. Existing test updated: tests/models/test_data_models.py (asserted on the old warning string).

Full suite: 241 passed, 57 skipped, 0 failed (excluding test_plexos_regression.py, which fails identically with or without this change -- confirmed pre-existing, a local fixture-data mismatch unrelated to this PR).

🤖 Generated with Claude Code

…ty (#22)

Closes the remaining part of #22: a plain `import gat` inherited
loguru's untouched default sink, which shows every DEBUG-level call
across the codebase (~90 call sites), not just the plot-function
registration noise originally reported.

- gat/__init__.py: on first import, if loguru is still at its
  pristine single-handler state, set the same quiet default the CLI
  already uses for itself (WARNING). Never touches an already-
  configured sink -- verified a caller's own logger.add()/remove()
  survives `import gat` untouched, and CLI's own setup_cli_logging()
  still overrides normally. warnings.warn(...), the channel GAT uses
  for actionable notices, is untouched either way.
- models/scenario.py: the "no fuzzy match, assigning random color"
  warning didn't explain how to fix it, unlike its sibling
  fuzzy-match warning -- now it does (technology_mappings config
  override).
- scenariohandlers/multi.py: MultiScenario._concat_gat_df silently
  unioned differing scenario timestamp indexes via
  pd.concat(axis=1), introducing NaN rows with no signal when
  scenarios cover different date ranges/resolutions. Now warns with
  each scenario's actual range.

Verified with a fresh interpreter/subprocess, not just reasoning:
DEBUG spam gone, WARNING-level still visible, a pre-existing sink
survives import, and the two new warnings fire/don't fire on
synthetic misaligned/aligned cases respectively.
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.

1 participant