Skip to content

Add a context manager as an alternative to monkey patching#91

Merged
OriolAbril merged 7 commits into
arviz-devs:mainfrom
krokosik:feat-default-dims-context-manager
Jun 10, 2026
Merged

Add a context manager as an alternative to monkey patching#91
OriolAbril merged 7 commits into
arviz-devs:mainfrom
krokosik:feat-default-dims-context-manager

Conversation

@krokosik

Copy link
Copy Markdown
Contributor

Closes #29

@read-the-docs-community

read-the-docs-community Bot commented Apr 15, 2026

Copy link
Copy Markdown

Comment thread src/xarray_einstats/__init__.py Outdated


@contextmanager
def default_linalg_dims(func_or_dims):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the body can be kept mostly as is, the only change is I would define it inside the linalg.py file so it is also imported from xarray_einstats.linalg instead of being available at the top level. We might then want to remove the linalg from the name but I am also fine keeping it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done and removed the linalg part

Comment thread src/xarray_einstats/__init__.py Outdated
Comment on lines +211 to +213
Yields
------
None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

numpydoc doesn't say anything on documenting context managers but I would remove this section and instead add an examples section or a seealso pointing to the docs on using it. In general I would also update all the docs to remove any reference to monkeypatching and rely on the context manager only (I am more than happy to do this myself if you prefer).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made some changes and added missing sections

@OriolAbril OriolAbril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like the linting check is complaining, you should be able to fix it with tox -e reformat, after that it's good to merge. Thanks for the contributions and the patience ❤️

@krokosik krokosik force-pushed the feat-default-dims-context-manager branch from 63d9042 to 5712455 Compare June 9, 2026 11:09
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.50%. Comparing base (2dcbd7e) to head (5712455).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/xarray_einstats/linalg.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
+ Coverage   91.46%   91.50%   +0.03%     
==========================================
  Files           6        6              
  Lines         844      859      +15     
==========================================
+ Hits          772      786      +14     
- Misses         72       73       +1     

☔ 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.

@krokosik

krokosik commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

fixed :)

@OriolAbril OriolAbril merged commit 2b78722 into arviz-devs:main Jun 10, 2026
6 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.

Change the monkeypatch thing to using with contexts?

2 participants