Fix series length ordering for string[python] IDs in dataframe validation/conversion#470
Open
dario-fumarola wants to merge 1 commit intoamazon-science:mainfrom
Open
Conversation
This file contains hidden or 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
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.
Summary
Fixes #440 by making series-length extraction deterministic and aligned with row order, including when
id_columnuses pandasstring[python]dtype.Root cause
After sorting by
(id_column, timestamp_column), the code used:value_counts(sort=False).to_list()to derive per-series lengths. For some ID dtypes (notably
string[python]), this can produce an order that does not match contiguous row blocks, which then misaligns timestamp slicing and can trigger false frequency inference failures.Changes
validate_df_inputs, replaced:df[id_column].value_counts(sort=False).to_list()df.groupby(id_column, sort=False).size().to_list()convert_df_input_to_list_of_dicts_inputwhenvalidate_inputs=Falsefor consistency.test_validate_df_inputs_accepts_string_python_ids_with_unequal_lengthstest_validate_df_inputs_has_consistent_metadata_for_object_and_string_python_idstest_convert_df_with_validate_inputs_false_handles_string_python_idsValidation
pytest test/test_df_utils.py(36 passed)mypy src test(no issues)Compatibility
No public API changes. Behavior is unchanged except for correcting dtype-dependent ordering/misalignment.