Improve typing consistency in codebase#1311
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1311 +/- ##
==========================================
- Coverage 87.98% 84.11% -3.88%
==========================================
Files 31 31
Lines 6027 6447 +420
==========================================
+ Hits 5303 5423 +120
- Misses 724 1024 +300 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ns-rse
left a comment
There was a problem hiding this comment.
Good work tackling this behemoth of a task @ubdbra001 and apologies for it being so messy (typing only came onto my radar way after I'd started).
Some comments in-line from a quick scan, don't have time to investigate more deeply I'm afraid.
| grain_stats_df.index.set_names(["grain_number", "class", "subgrain"], inplace=True) | ||
| else: | ||
| grain_stats_df = None | ||
| return topostats_object.filename, topostats_object, grain_stats_df |
There was a problem hiding this comment.
Not for this work but I thought I'd removed returning of dataframes as they are instead pulled out of the topostats_objects and collated into a dictionary before converting to pd.DataFrame.
There was a problem hiding this comment.
This was the only one I've spotted so far, happy to open an issue to be addressed later
There was a problem hiding this comment.
Note it as an issue, its at least then recorded and can be addressed if anyone has time/inclination.
SylviaWhittle
left a comment
There was a problem hiding this comment.
Just a thing I noticed skim-reading this.
| @@ -214,7 +214,7 @@ def compile_images( | |||
| @staticmethod | |||
| def remove_common_values( | |||
| ordered_array: npt.NDArray, common_value_check_array: npt.NDArray, retain: list = () | |||
There was a problem hiding this comment.
On this:
retainis typed aslisttype but being assigned an emptytupleby default 🤔- Setting the default value to an empty
listmay cause issues (see here).
I'll probably set it as None and add a check so that it get re-set to an empty list if the arg is not supplied.
Any objections?
There was a problem hiding this comment.
This is a good solution and yeah, default args should not be data structures as you point out.
| molecule_data : dict[int, Molecule], optional | ||
| Dictionary of ``Molecule`` objects indexed by molecule number. | ||
| tracing_stats : dict | None | ||
| tracing_stats : dict, optional |
There was a problem hiding this comment.
I have been going around replacing | None with , optional in the docstrings. Probably doesn't have a real impact but I thought I'd make it all consistent.
Let me know if you'd prefer to retain | None
| Dictionary, indexed by molecule where the value is the molecules statistics for the given molecule. | ||
| """ | ||
| if self.molecule_data is None: | ||
| raise ValueError("No molecule data found") |
There was a problem hiding this comment.
Let me know if you'd like me to change this to something else
ns-rse
left a comment
There was a problem hiding this comment.
Some responses in-line...
| grain_stats_df.index.set_names(["grain_number", "class", "subgrain"], inplace=True) | ||
| else: | ||
| grain_stats_df = None | ||
| return topostats_object.filename, topostats_object, grain_stats_df |
There was a problem hiding this comment.
Note it as an issue, its at least then recorded and can be addressed if anyone has time/inclination.
|
Just a thought but it might be worth adding commits to |
|
I think I've got all the low hanging typing fruit, anything else this will cause tests to fail and so I suspect will require a bit more discussion. |
resolves typing error for later "molecule_data[i] = ..." as NoneType is not sub-scriptable
Raises valueError if molecule_data is None
Adds correct return typehint Co-authored-by: Neil Shephard <n.shephard@sheffield.ac.uk>
Add correct return type hint Co-authored-by: Sylvia Whittle <86117496+SylviaWhittle@users.noreply.github.com>
Correct to a tuple of str and dict
Corrects the type hint and the docstring
Docstring for second value in return tuple needs to be updated
These specify that the values in the dict are not None after processing
However, I don' see these being used anywhere, so it may be worth just deleting?
To match return value type hint
Currently very broad value type, I couldn't parse what they could be from the code
9328755 to
f627bd9
Compare
| @@ -214,7 +214,7 @@ def compile_images( | |||
| @staticmethod | |||
| def remove_common_values( | |||
| ordered_array: npt.NDArray, common_value_check_array: npt.NDArray, retain: list = () | |||
There was a problem hiding this comment.
This is a good solution and yeah, default args should not be data structures as you point out.
|
Looked at all changes and have provided answers to queries for docstrings. This is good to go once the docstrings are updated and provided tests pass. Thank you very much @ubdbra001. |
Fix #1299
This PR addresses the inconsistent typing in the codebase.
Given the size of this I'm going to do it incrementally in this PR. The initial stage of this is picking out the "easy wins" e.g. cases where the type hints are missing or incorrect and are easy/obvious to update.
At this stage all the tests still pass.
Before submitting a Pull Request please check the following.
docs/configuration.mddocs/usage.mddocs/data_dictionary.mddocs/advanced.mdand new pages it should link to.