Skip to content

Stop adiftools import from overriding notebook matplotlib backend#14

Merged
JS2IIU-MH merged 6 commits intomainfrom
copilot/fix-notebook-plotting-issue
May 5, 2026
Merged

Stop adiftools import from overriding notebook matplotlib backend#14
JS2IIU-MH merged 6 commits intomainfrom
copilot/fix-notebook-plotting-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Importing adiftools.adiftools in Kaggle/Jupyter disabled inline plotting because adifgraph changed matplotlib’s global backend to Agg at import time. This PR removes that import side effect so notebook plotting remains functional after importing the library.

  • Backend behavior

    • Removed import-time backend override from adiftools/adifgraph.py:
      • deleted matplotlib.use('Agg')
      • removed now-unused import matplotlib
    • adiftools no longer mutates global matplotlib backend during import.
  • Regression coverage

    • Added a focused test in tests/test_adifgraph.py to assert adifgraph import does not call matplotlib.use.
def test_import_does_not_force_matplotlib_backend(monkeypatch):
    calls = []

    def spy_use(*args, **kwargs):
        calls.append((args, kwargs))

    monkeypatch.setattr(matplotlib, 'use', spy_use)
    importlib.reload(adifgraph)

    assert calls == []

Copilot AI and others added 5 commits May 5, 2026 01:33
Agent-Logs-Url: https://github.com/JS2IIU-MH/adiftools-dev/sessions/16d535a8-1297-4bbf-8e18-ebb0929af222

Co-authored-by: JS2IIU-MH <146515386+JS2IIU-MH@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix notebook plotting issue when importing adiftools Stop adiftools import from overriding notebook matplotlib backend May 5, 2026
Copilot AI requested a review from JS2IIU-MH May 5, 2026 01:37
@JS2IIU-MH JS2IIU-MH marked this pull request as ready for review May 5, 2026 01:41
Copilot AI review requested due to automatic review settings May 5, 2026 01:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes an import-time matplotlib side effect from adiftools.adifgraph so importing the library no longer forces the global backend to Agg, which preserves inline plotting behavior in notebook environments.

Changes:

  • Removed the import-time matplotlib.use('Agg') call and the now-unused matplotlib import from adiftools/adifgraph.py.
  • Added a regression test that reloads adifgraph and asserts it does not call matplotlib.use.
  • Kept the change narrowly scoped to backend side effects and their coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
adiftools/adifgraph.py Removes the module-level backend override that was mutating matplotlib state during import.
tests/test_adifgraph.py Adds a regression test verifying adifgraph import/reload no longer invokes matplotlib.use.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JS2IIU-MH JS2IIU-MH merged commit bcfd9a8 into main May 5, 2026
19 checks passed
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.

importing adiftools changes/prevents notebook plotting in a kaggle notebook

3 participants