Skip to content

Fix remove_incomplete_samples TypeError on string data with nan_strategy='drop' - #179

Open
Jefferyjia wants to merge 1 commit into
shakedzy:masterfrom
Jefferyjia:fix/remove-incomplete-samples-object-dtype
Open

Jefferyjia wants to merge 1 commit into
shakedzy:masterfrom
Jefferyjia:fix/remove-incomplete-samples-object-dtype

Conversation

@Jefferyjia

Copy link
Copy Markdown

Closes #178

Problem

remove_incomplete_samples (backing nan_strategy='drop' in cramers_v, theils_u, correlation_ratio and associations) raises TypeError: ufunc 'isnan' not supported on any string input — including clean data with no missing values. For string lists containing None, numpy coerces np.nan into 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)

  • Build the sample-pair array with dtype=object, so None/np.nan stay null sentinels instead of being coerced to "nan" strings or crashing np.isnan.
  • Mask with pd.isnull instead of np.isnan — elementwise null detection that works for strings, numerics, None, np.nan and pd.NaT.

Tests

  • tests/test_private_helpers.py: string+None and string+np.nan cases for remove_incomplete_samples, asserting exact rows dropped.
  • tests/test_nominal/test_inf_nan_handling.py: regression tests for cramers_v / theils_u / correlation_ratio with nan_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 unmodified master in this environment (pandas 3.1.1 / sklearn) and are unrelated to this change — verified by running the same tests on master before the fix.

Checklist

  • Behavior for numeric data is unchanged (existing remove_incomplete_samples tests pass as-is)
  • Follows existing code style

This fix and its tests were prepared with AI assistance (Claude); reviewed and submitted by a human.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: ufunc 'isnan' not supported — nan_strategy='drop' crashes on string data (and silently keeps None rows)

1 participant