Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tuple as input type in parse_excel.infer_metadata() #213

Merged
merged 6 commits into from
Feb 15, 2024

Conversation

ajeklund
Copy link
Contributor

@ajeklund ajeklund commented Feb 2, 2024

Description:

parse_excel.infer_metadata() expects its input parameter units as a list, but we want to send a tuple from get(). Suggested solution is to add handling of tuple.

Closes #212.

Type of change:

  • Bug fix.
  • New feature.
  • Documentation update.

Checklist for the reviewer:

This checklist should be used as a help for the reviewer.

  • Is the change limited to one issue?
  • Does this PR close the issue?
  • Is the code easy to read and understand, including clearly named variables?
  • Do all new feature have an accompanying new test?
  • Has the documentation been updated as necessary?

@ajeklund ajeklund linked an issue Feb 2, 2024 that may be closed by this pull request
Copy link
Contributor

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Is there are case where units is actually a list? Or is it always (now) a tuple? If so, the list type should simply be changed to tuple without the Union.

Copy link

codecov bot commented Feb 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a7bcd3a) 88.67% compared to head (7a697c8) 88.67%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #213   +/-   ##
=======================================
  Coverage   88.67%   88.67%           
=======================================
  Files          15       15           
  Lines         459      459           
=======================================
  Hits          407      407           
  Misses         52       52           
Flag Coverage Δ
linux 88.67% <100.00%> (ø)
windows 88.59% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ajeklund
Copy link
Contributor Author

ajeklund commented Feb 2, 2024

Is there are case where units is actually a list? Or is it always (now) a tuple? If so, the list type should simply be changed to tuple without the Union.

No, it is only called using a tuple. I've now committed the suggested change.

@CasperWA
Copy link
Contributor

CasperWA commented Feb 3, 2024

If you want to make it even more accurate, you can pass in the types that will be contained in the tuple, for example if it's two strings: tuple[str, str], or if it's a string first and then a boolean (True/False) then it would be: tuple[str, bool].
If it's an unknown number of the same type that will be contained, ellipsis (...) can be used, for example, if it will be an unknown number of strings it would be: tuple[str, ...].

@@ -153,7 +153,7 @@ def split_column_name(column):
return name, unit


def infer_metadata(rec: np.recarray, units: list) -> dlite.Instance:
def infer_metadata(rec: np.recarray, units: tuple) -> dlite.Instance:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since any sequence will work, I will suggest to state that explicitly:

Suggested change
def infer_metadata(rec: np.recarray, units: tuple) -> dlite.Instance:
def infer_metadata(rec: np.recarray, units: "Sequence") -> dlite.Instance:

This requires that we load from typing import Sequence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but this does not work together with @CasperWA's suggestion to also specify an unknown number of strings. (That results in TypeError: Parameters to generic types must be types. Got Ellipsis.). I will hence go for tuple[str, ...].

@ajeklund
Copy link
Contributor Author

If you want to make it even more accurate, you can pass in the types that will be contained in the tuple, for example if it's two strings: tuple[str, str], or if it's a string first and then a boolean (True/False) then it would be: tuple[str, bool]. If it's an unknown number of the same type that will be contained, ellipsis (...) can be used, for example, if it will be an unknown number of strings it would be: tuple[str, ...].

Thank you! I implemented the tuple[str, ...] suggestion.

@ajeklund ajeklund merged commit a5118ca into master Feb 15, 2024
10 checks passed
@ajeklund ajeklund deleted the 212-mypy-update-detects-new-type-error branch February 15, 2024 09:04
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.

mypy update detects new type error
3 participants