(refactor) remove redundant logic in _check_valid_index_key #7490
+3
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contributes a minor refactor, in a small function in
src/datasets/formatting/formatting.py
. No change in logic.In the original code, there are separate if-conditionals for
isinstance(key, range)
andisinstance(key, Iterable)
, with essentially the same logic.This PR combines these two using a single if statement.
Considerations
Although range in python is guaranteed to have integers, internally calling
int()
on an object that is already an int is negligible. (In python it returns the original object. It doesn't create a new integer object or perform any actual conversion)Technically a range is already an Iterable, and we could just do
isinstance(key, Iterable)
but I explicitly didisinstance(key, (range, Iterable))
just to be super obvious and consistent that both cases are handled because I seeslice, range, Iterable
everywhere in thisformatting.py
This PR removes the
if len(key)>0
conditional. I think it is cleaner to have it this way for three reasons.formatting.py
.Previous PR and Issues Checks
Tests