Skip to content

Commit acd303e

Browse files
String dtype: honor mode.string_storage option (and change default to None)
1 parent ecc451d commit acd303e

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

pandas/core/arrays/string_.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ def __init__(
140140
# infer defaults
141141
if storage is None:
142142
if na_value is not libmissing.NA:
143-
if HAS_PYARROW:
144-
storage = "pyarrow"
145-
else:
146-
storage = "python"
147-
else:
148143
storage = get_option("mode.string_storage")
144+
if storage is None:
145+
if HAS_PYARROW:
146+
storage = "pyarrow"
147+
else:
148+
storage = "python"
149+
else:
150+
storage = get_option("mode.string_storage") or "python"
149151

150152
if storage == "pyarrow_numpy":
151153
# TODO raise a deprecation warning

pandas/core/config_init.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,12 @@ def is_terminal() -> bool:
452452

453453
string_storage_doc = """
454454
: string
455-
The default storage for StringDtype. This option is ignored if
456-
``future.infer_string`` is set to True.
455+
The default storage for StringDtype.
457456
"""
458457

459458

460459
def is_valid_string_storage(value: Any) -> None:
461-
legal_values = ["python", "pyarrow"]
460+
legal_values = [None, "python", "pyarrow"]
462461
if value not in legal_values:
463462
msg = "Value must be one of python|pyarrow"
464463
if value == "pyarrow_numpy":
@@ -473,7 +472,7 @@ def is_valid_string_storage(value: Any) -> None:
473472
with cf.config_prefix("mode"):
474473
cf.register_option(
475474
"string_storage",
476-
"python",
475+
None,
477476
string_storage_doc,
478477
# validator=is_one_of_factory(["python", "pyarrow"]),
479478
validator=is_valid_string_storage,

pandas/tests/arrays/string_/test_string_arrow.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
from pandas.compat import HAS_PYARROW
87
import pandas.util._test_decorators as td
98

109
import pandas as pd
@@ -28,11 +27,6 @@ def test_eq_all_na():
2827

2928

3029
def test_config(string_storage, request, using_infer_string):
31-
if using_infer_string and string_storage == "python" and HAS_PYARROW:
32-
# string storage with na_value=NaN always uses pyarrow if available
33-
# -> does not yet honor the option
34-
request.applymarker(pytest.mark.xfail(reason="TODO(infer_string)"))
35-
3630
with pd.option_context("string_storage", string_storage):
3731
assert StringDtype().storage == string_storage
3832
result = pd.array(["a", "b"])

0 commit comments

Comments
 (0)