-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Reject zero-level Index results from string expansion #24078
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
Open
galipremsagar
wants to merge
3
commits into
NVIDIA:main
Choose a base branch
from
galipremsagar:fix/pandas-empty-index-partition
base: main
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 50368
🤖 get_repo_knowledge executed:
get_repo_knowledge NVIDIA/cudf /tmp/coderabbit-repo-knowledge/nvidia-cudf-5d380a13/conventions /tmp/coderabbit-repo-knowledge/nvidia-cudf-5d380a13/learningsLength of output: 8614
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 50367
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 28553
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 11671
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 10784
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 215
🌐 Web query:
site:github.com/rapidsai/cudf "Cannot infer number of levels from empty list" base_accessor.py💡 Result:
The error message "Cannot infer number of levels from empty list" is typically associated with the cuDF library, specifically occurring during operations involving MultiIndex handling or column accessor initialization when data structures are empty or improperly formatted [1][2]. While there is no single, globally defined exception in the public pandas or cuDF API with this exact string, it points to a validation failure in how cuDF processes hierarchical data (like MultiIndex levels or nested list columns) [1][2]. Common causes and contexts for this issue include: 1. MultiIndex Construction: It often appears when trying to create or process a MultiIndex where the levels or codes are passed as an empty sequence (e.g., an empty list) [1]. MultiIndex objects require valid, non-empty level sequences [1]. 2. Internal Accessor Registration: As cuDF frequently refactors its accessor architecture (e.g., moving accessors from
cudf/core/columnto dedicated namespaces) [2], issues can arise when a property accessor (like.listor.str) is invoked on an empty column that does not properly reflect the expected metadata/type structure required for that accessor [3][2]. 3. Data Invariants: cuDF strictly enforces Arrow-compatible invariants for its column formats [4][5]. Operations on empty list columns that do not satisfy these internal memory layout requirements—such as having an offset array size that does not match the expected row count—often trigger validation errors during read or conversion operations [4][5]. To troubleshoot this: - Verify that your input data is not an empty list or an empty DataFrame if you are attempting to construct a MultiIndex [1]. - Check for pandas compatibility mode settings (e.g.,cudf.set_option("mode.pandas_compatible", True)), as this sometimes alters how empty indexes are handled [6]. - If you are using a specific version of cuDF, ensure your code is not relying on deprecated internal APIs, as recent updates have moved accessor implementations and removed internal cached accessors [7][2]. - If you can reproduce this with a minimal example, it is recommended to open an issue on the RAPIDS cuDF GitHub repository, as these errors are often tied to specific internal validation logic inpylibcudfor the Python-side wrappers [4][6].Citations:
🏁 Script executed:
Repository: NVIDIA/cudf
Length of output: 166
🌐 Web query:
pandas Index str split expand=True empty Index partition extract behavior official documentation source💡 Result:
In pandas, the
Index.str.splitmethod withexpand=Trueis designed to transform string elements in an Index into a MultiIndex by splitting them into separate components [1][2]. Behavioral and technical considerations include: 1. Return Type: According to the official documentation, whenexpand=Trueis used on an Index, the method returns a MultiIndex [1][2]. Ifexpand=False(the default), it returns an Index containing lists of strings [1][2]. 2. Dimensionality and Splitting: The number of levels in the resulting MultiIndex depends on the number of splits performed. If a string cannot be split (e.g., the delimiter is not found), the behavior may vary depending on the pandas version; historically, some users have encountered unexpected behavior where the return type is not a MultiIndex in cases where no splits occur [3]. 3. Empty/Missing Data: - Empty Strings: Splitting an empty string typically results in an empty sequence or is handled gracefully in modern versions, though early versions (pre-0.22) faced exceptions [4]. - NaN Handling:Index.str.splitwithexpand=Trueis not always fully "NaN-safe" across all historical versions and edge cases, sometimes triggering TypeErrors if the index contains non-string types like floats [5]. 4. Practical Limitations: When working withexpand=True, the number of resulting columns (or levels) is dynamic, based on the input data. If you are assigning these results to a DataFrame or performing further operations, ensure your code accounts for cases where the split might yield fewer columns than expected (e.g., when data is missing or strings are inconsistent), as this can cause mismatches in dimensions [6]. For robust workflows, it is often recommended to verify the output shape or structure if your downstream logic depends on a fixed number of levels or columns, especially when dealing with heterogeneous or potentially incomplete string data [6].Citations:
🌐 Web query:
site:pandas.pydata.org/docs/reference/api pandas Index.str.partition empty Index MultiIndex💡 Result:
In pandas, when using Index.str.partition on an empty Index, the behavior depends on the parameters provided, particularly the default expand=True behavior. When you call str.partition on an empty Index, it returns an empty MultiIndex [1][2]. By design, this method splits strings into three parts (before, separator, after) and, by default, expands these into a MultiIndex to hold the resulting structure [1][2]. If the input Index is empty, the result retains this structure but contains no elements [3]. Key behaviors: 1. Default (expand=True): Calling idx.str.partition on an empty Index results in an empty MultiIndex [1][2]. 2. Alternative (expand=False): If you specify expand=False, the method returns an empty Index containing tuples rather than a MultiIndex [1][2]. An Index is considered empty if it contains no elements [3]. Because the str accessor methods are vectorized to handle the contents of the Index, they generally propagate the empty state of the underlying data while preserving the expected return type (e.g., a MultiIndex for expanded output) [1][2].
Citations:
🌐 Web query:
site:github.com/pandas-dev/pandas "Index([], dtype" "str.partition" MultiIndex💡 Result:
The string 'Index([], dtype=str)' appearing alongside a MultiIndex in pandas typically indicates that a string operation (accessed via the.str accessor) has been performed on a pandas Index object that contains string data, resulting in a structured, multi-level output [1][2]. Specifically, when using methods like str.partition or str.split on a pandas Index with expand=True (the default), pandas returns a MultiIndex rather than a standard Index to represent the split components of the strings [1][3]. For example, performing a partition on an index: idx = pd.Index(["X 123", "Y 999"]) # This creates a MultiIndex idx.str.partition If you encounter an Index object with dtype=str or dtype=object appearing in your output when working with these methods, it is often because expand=False was specified, which forces the operation to return an Index containing tuples or objects instead of expanding into a MultiIndex [1][2][3]. Key points regarding this behavior: 1. MultiIndex output: Operations like.str.partition or.str.split naturally return a MultiIndex when expanding the results [1]. 2. expand parameter: You can control this behavior using the expand parameter. Setting expand=False will return an Index of objects (containing the resulting tuples) instead of a MultiIndex [1][3]. 3. Method functionality: These operations are designed to handle string data within Index objects, provided the underlying data consists of strings [4][5]. Note that these accessors generally do not work on MultiIndex objects themselves [4][5].
Citations:
Limit the guard to zero-column expanded results.
Pandas returns an empty three-level
MultiIndexforIndex.str.partitionandIndex.str.rpartition. The currentlen(table) == 0check raises instead for these fixed-width results. Keep theTypeErroronly when the expanded result has no columns.🤖 Prompt for AI Agents