Skip to content

Add type hints to all of src - #483

Merged
larsevj merged 3 commits into
mainfrom
fix_typing
Nov 5, 2025
Merged

Add type hints to all of src#483
larsevj merged 3 commits into
mainfrom
fix_typing

Conversation

@larsevj

@larsevj larsevj commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

Needs #482

@codecov-commenter

codecov-commenter commented Oct 30, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.78%. Comparing base (095e1bf) to head (e991b97).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #483      +/-   ##
==========================================
+ Coverage   98.75%   98.78%   +0.03%     
==========================================
  Files          17       16       -1     
  Lines        2723     2628      -95     
==========================================
- Hits         2689     2596      -93     
+ Misses         34       32       -2     

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

Copilot AI left a comment

Copy link
Copy Markdown

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 adds comprehensive type hints to the pyscal codebase. The changes modernize the codebase by adding proper type annotations throughout the source files and adjusting imports to support type checking.

  • Adds type hints to function parameters, return types, and variable declarations
  • Updates import statements to include type checking dependencies
  • Refactors variable names to avoid shadowing built-in types

Reviewed Changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/*.py Updates imports from pyscal.utils.testing to tests.utils
src/pyscal/wateroil.py Adds type hints, imports matplotlib at top level, adds type: ignore comments for pandas operations
src/pyscal/utils/string.py Adds return type annotation to comment_formatter function
src/pyscal/utils/relperm.py Adds type hints to truncate_zeroness function and pandas operations
src/pyscal/utils/monotonicity.py Adds type: ignore comments for pandas diff operations
src/pyscal/utils/interpolation.py Adds comprehensive type hints and imports numpy.typing
src/pyscal/utils/capillarypressure.py Adds union type hints for pandas Series support
src/pyscal/pyscallist.py Adds type hints to init and getitem methods
src/pyscal/pyscalcli.py Renames parametertable variable to avoid shadowing
src/pyscal/plotting.py Adds TypedDict for kwargs and comprehensive type hints
src/pyscal/gaswater.py Adds type hints and imports matplotlib at top level
src/pyscal/gasoil.py Adds type hints and imports matplotlib at top level
src/pyscal/factory.py Adds comprehensive type hints and fixes variable shadowing
pyproject.toml Updates ruff configuration and adds type checking dependencies
docs/make_plots.py Adds type hints to all function definitions

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

Comment thread src/pyscal/factory.py
Comment thread tests/utils.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

any risk that someone using this API in their script?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I guess there is a risk for it, although the file docstring says the following:

"""Common functions and mock data for usage in pyscal testing"""

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Of the equinor repos I could only find usage of it in one subscript test.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good point. I guess we can just try it out first 👍

@larsevj
larsevj force-pushed the fix_typing branch 3 times, most recently from 8818aa9 to 0200888 Compare November 4, 2025 08:27
@larsevj
larsevj requested a review from Copilot November 4, 2025 08:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 5 comments.


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

Comment thread src/pyscal/utils/monotonicity.py
Comment thread src/pyscal/factory.py
Comment thread src/pyscal/plotting.py
Comment thread src/pyscal/utils/interpolation.py Outdated
Comment thread src/pyscal/utils/capillarypressure.py
@larsevj
larsevj requested a review from alifbe November 4, 2025 08:47
Comment thread src/pyscal/utils/interpolation.py Outdated
# are there or even correct, therefore we effectively
# recalculate them
def sw_fn(swn):
def sw_fn(swn: pd.Series) -> pd.Series:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just curious, why not numpy array here instead of pandas series?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I thought it was only used with pandas series internally, but have tried an alternative approach now.

Comment thread src/pyscal/gaswater.py
def plotkrwkrg(
self,
mpl_ax=None,
mpl_ax: Optional[matplotlib.axes.Axes] = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not matplotlib.axes.Axes | None = None

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will have a separate pr to add ruff rule UP that automatically modernizes the typing

Comment thread src/pyscal/plotting.py Outdated


def format_relperm_plot(fig: plt.Figure, **kwargs) -> plt.Figure:
def format_relperm_plot(fig: plt.Figure, **kwargs: Any) -> plt.Figure: # noqa: ANN401

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we use Unpack[PlotKwargs] as well here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Have refactored this now to avoid Any

@alifbe alifbe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. Just some question out of curiosity. But I think ideally we'd like to avoid Any type.

@larsevj
larsevj force-pushed the fix_typing branch 4 times, most recently from 96c3af5 to c5994a4 Compare November 4, 2025 12:53
@larsevj
larsevj requested a review from Copilot November 5, 2025 11:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

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


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

Comment thread src/pyscal/utils/interpolation.py Outdated
Comment thread src/pyscal/factory.py
@larsevj
larsevj merged commit 584bc54 into main Nov 5, 2025
6 checks passed
@larsevj
larsevj deleted the fix_typing branch November 5, 2025 11:47
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.

4 participants