Repository navigation
Fix remove_incomplete_samples TypeError on string data with nan_strategy='drop' - #179
Open
Jefferyjia wants to merge 1 commit into
Open
Jefferyjia wants to merge 1 commit into
Jefferyjia wants to merge 1 commit into
Conversation
…strategy='drop' remove_incomplete_samples built a 2D numpy array from x and y and called np.isnan on it, which raises TypeError for string (object/str dtype) data - the primary use case of cramers_v/theils_u. For string inputs, None values were also coerced to the literal string 'nan' by numpy, so rows containing None were never dropped even before the crash. Build the array with dtype=object and use pd.isnull for the mask, which handles None, np.nan and pd.NaT for both numeric and categorical data.
This branch has not been deployed
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.
Closes #178
Problem
remove_incomplete_samples(backingnan_strategy='drop'incramers_v,theils_u,correlation_ratioandassociations) raisesTypeError: ufunc 'isnan' not supportedon any string input — including clean data with no missing values. For string lists containingNone, numpy coercesnp.naninto the literal string'nan', so incomplete rows are silently kept as a"nan"category instead of being dropped. See #178 for full reproduction.Fix (
dython/_private.py, 2 lines)dtype=object, soNone/np.nanstay null sentinels instead of being coerced to"nan"strings or crashingnp.isnan.pd.isnullinstead ofnp.isnan— elementwise null detection that works for strings, numerics,None,np.nanandpd.NaT.Tests
tests/test_private_helpers.py: string+Noneand string+np.nancases forremove_incomplete_samples, asserting exact rows dropped.tests/test_nominal/test_inf_nan_handling.py: regression tests forcramers_v/theils_u/correlation_ratiowithnan_strategy='drop'on string data (previously all crashed).Full suite: 231 passed. The 6 failures (
test_cluster_correlation*,test_numerical_encoding_with_nan_replace) are pre-existing on unmodifiedmasterin this environment (pandas 3.1.1 / sklearn) and are unrelated to this change — verified by running the same tests onmasterbefore the fix.Checklist
remove_incomplete_samplestests pass as-is)This fix and its tests were prepared with AI assistance (Claude); reviewed and submitted by a human.