Use native factorization for object string categories

HA
4d ago
+176-18

Summary

Fixes #471

  • Add a safe native factorization path for homogeneous object-backed
    string categories.

  • Preserve existing fallback behavior for mixed objects, null-like values,
    bytes, and custom string semantics.

  • Keep the existing low-cardinality probe as the fast-path gate.

  • Preserve category ordering, codes, and count semantics.

  • Add regression coverage proving only unique labels cross the Python
    label path.

Testing

  • tests/test_custom_ramps_and_palette.py: 92 passed, 1 skipped
  • tests/test_components.py: 103 passed
  • Ruff check and format passed
  • git diff --check passed

Summary by CodeRabbit

  • Bug Fixes

    • Improved categorical handling for object arrays containing only exact Python strings, keeping category order, codes, counts, and distinct labels consistent with fixed-width string arrays.
    • Preserved distinct categories containing NUL characters and fallback behavior for mixed or unsupported values.
    • Limited distinct-count probing and sampling when assessing near-unique categories.
  • Tests

    • Added coverage for string-only, NUL-containing, near-unique, and mixed-value categories.