Ray's Knowledge Base
Unlock

pandas 3 gives string columns the str dtype, not object

PitfallVerified 1 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A test or golden-output generator that expects object for a string column fails under pandas 3. Cases with null keys errored first, because the generator handled the object path only.

Cause#

pandas 3 uses a dedicated str dtype for string columns by default. pandas 2 used object.

Fix#

Compare values, not the dtype name, or accept both str and object for string columns. When a generator branches on dtype, handle str the same way as object.

Evidence#

A dftracer-utils group_by golden-output generator, written by a subagent, errored on null-key cases; the agent reported the cause as the pandas 3 str dtype and regenerated the cases. Taken from the agent's report, not rerun.

Also found by searching

  • pandas string column dtype is str instead of object
  • golden output generator errors on null keys with pandas 3
  • why does my test expect object dtype but pandas gives str
  • pandas 3 default string dtype broke a comparison