-
Notifications
You must be signed in to change notification settings - Fork 2
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
prepare_iter_for_array PR #43
Open
chaburkland
wants to merge
23
commits into
static-frame:master
Choose a base branch
from
chaburkland:9/prepare_iter_for_array
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
prepare_iter_for_array PR #43
chaburkland
wants to merge
23
commits into
static-frame:master
from
chaburkland:9/prepare_iter_for_array
+674
−8
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…d enum type check.
Current performance
|
…_max_coercible_to_float.
I have optimized the Python implementation of this function, which reduces and clarifies the requirements of this function. The new implementation is as follows: def prepare_iter_for_array(
values: tp.Iterable[tp.Any],
restrict_copy: bool = False
) -> tp.Tuple[DtypeSpecifier, bool, tp.Sequence[tp.Any]]:
is_gen, copy_values = is_gen_copy_values(values)
if not is_gen and len(values) == 0: #type: ignore
return None, False, values #type: ignore
if restrict_copy:
copy_values = False
v_iter = values if is_gen else iter(values)
if copy_values:
values_post = []
resolved = None # None is valid specifier if the type is not ambiguous
has_tuple = False
has_str = False
has_non_str = False
has_inexact = False
has_big_int = False
for v in v_iter:
if copy_values:
# if a generator, have to make a copy while iterating
values_post.append(v)
value_type = type(v)
if (value_type is str
or value_type is np.str_
or value_type is bytes
or value_type is np.bytes_):
# must compare to both string types
has_str = True
elif hasattr(v, '__len__'):
# identify SF types by if they have STATIC attr they also must be assigned after array creation, so we treat them like tuples
has_tuple = True
resolved = object
break
elif isinstance(v, Enum):
# must check isinstance, as Enum types are always derived from Enum
resolved = object
break
else:
has_non_str = True
if value_type in INEXACT_TYPES:
has_inexact = True
elif value_type is int and abs(v) > INT_MAX_COERCIBLE_TO_FLOAT:
has_big_int = True
if (has_str and has_non_str) or (has_big_int and has_inexact):
resolved = object
break
if copy_values:
# v_iter is an iter, we need to finish it
values_post.extend(v_iter)
return resolved, has_tuple, values_post
return resolved, has_tuple, values #type: ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #9