pandas-dev / pandas-dev/pandas

TRACKER: new default String dtype (pyarrow-backed, numpy NaN semantics)

Open
#54,792 20 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API Design Arrow Strings
Dominant language
Python
Stars
49.8k
Forks
20.4k
Avg merge
1d 16h
Merged PRs (30d)
322

Description

Overview of work for the future string dtype (PDEP-14).

Main implementation:

Testing related:

Open design questions / behaviour changes to implement:

Known bugs that need to be fixed:

Documentation:


[original issue body]

With PDEP-10 (https://github.com/pandas-dev/pandas/pull/52711/, https://pandas.pydata.org/pdeps/0010-required-pyarrow-dependency.html), we decided to start using pyarrow for the default string data type in pandas 3.0.

For pandas 2.1, an option was added to already enable this future default data type, and then the various ways to construct a DataFrame (type inference in the constructor, IO methods) will use the new string dtype as default:

>>> pd.options.future.infer_string = True

>>> pd.Series(["a", "b", None])
0      a
1      b
2    NaN
dtype: string

>>> pd.Series(["a", "b", None]).dtype
string[pyarrow_numpy]

This is documented at https://pandas.pydata.org/docs/dev/whatsnew/v2.1.0.html#whatsnew-210-enhancements-infer-strings

One aspect that was discussed after the PDEP (mostly at the sprint, I think; creating this issue for a better public record of it), is that for a data type that would become the default in pandas 3.0 (which for the rest still uses all numpy dtypes with numpy NaN missing value semantics), should probably also still use the same default semantics and result in numpy data types when doing operations on the string column that result in a boolean or numeric data type (eg .str.startswith(..), .str.len(..), .str.count(), etc, or comparison operators like ==).
(this way, a user only gets an ArrowDtype column when explicitly asking for those, and not by default through using a the default string dtype)

To achieve this, @phofl has done several PRs to refactor the current pyarrow-based string dtypes, to add another variant which uses StringDtype(storage="pyarrow_numpy") instead of ArrowDtype("string"). From the updated whatsnew: "This is a new string dtype implementation that follows NumPy semantics in comparison operations and will return np.nan as the missing value indicator". Main PR:

plus some follow-ups (https://github.com/pandas-dev/pandas/pull/54720, https://github.com/pandas-dev/pandas/pull/54585, https://github.com/pandas-dev/pandas/pull/54591).

cc @pandas-dev/pandas-core

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the unchecked checklist items, especially issue #64560 for dtype=str/astype(str) aliases, issue #63105 for dtype-variant behavior and performance documentation, and the remaining IO-pytables tests. Confirm which items are still in scope and use the linked issues as the entry points; done means completing a specific unchecked item rather than the tracker as a whole.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.