<commit_before>import operator

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.common import is_dtype_equal

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.string_arrow import (
    ArrowStringArray,
    ArrowStringDtype,
)

skip_if_no_pyarrow = td.skip_if_no("pyarrow", min_version="1.0.0")


@pytest.fixture(
    params=["string", pytest.param("arrow_string", marks=skip_if_no_pyarrow)]
)
def dtype(request):
    return request.param


@pytest.fixture
def dtype_object(dtype):
    if dtype == "string":
        return pd.StringDtype
    else:
        return ArrowStringDtype


@pytest.fixture(
    params=[
        pd.arrays.StringArray,
        pytest.param(ArrowStringArray, marks=skip_if_no_pyarrow),
    ]
)
def cls(request):
    return request.param


def test_repr(dtype, request):
    if dtype == "arrow_string":
        reason = (
            "AssertionError: assert '      A\n0     a\n1  None\n2     b' "
            "== '      A\n0     a\n1  <NA>\n2     b'"
        )
        mark = pytest.mark.xfail(reason=reason)
        request.node.add_marker(mark)

    df = pd.DataFrame({"A": pd.array(["a", pd.NA, "b"], dtype=dtype)})
    expected = "      A\n0     a\n1  <NA>\n2     b"
    assert repr(df) == expected

    expected = "0       a\n1    <NA>\n2       b\nName: A, dtype: string"
    assert repr(df.A) == expected

    expected = "<StringArray>\n['a', <NA>, 'b']\nLength: 3, dtype: string"
    assert repr(df.A.array) == expected


def test_none_to_nan(cls):
    a = cls._from_sequence(["a", None, "b"])
    assert a[1] is not None
    assert a[1] is pd.NA


def test_setitem_validates(cls):
    arr = cls._from_sequence(["a", "b"])

    if cls is pd.arrays.StringArray:<commit_msg>TST: [ArrowStringArray] remove xfail from test_repr (#40678)<commit_after>import operator

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.common import is_dtype_equal

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.string_arrow import (
    ArrowStringArray,
    ArrowStringDtype,
)

skip_if_no_pyarrow = td.skip_if_no("pyarrow", min_version="1.0.0")


@pytest.fixture(
    params=["string", pytest.param("arrow_string", marks=skip_if_no_pyarrow)]
)
def dtype(request):
    return request.param


@pytest.fixture
def dtype_object(dtype):
    if dtype == "string":
        return pd.StringDtype
    else:
        return ArrowStringDtype


@pytest.fixture(
    params=[
        pd.arrays.StringArray,
        pytest.param(ArrowStringArray, marks=skip_if_no_pyarrow),
    ]
)
def cls(request):
    return request.param


def test_repr(dtype):
    df = pd.DataFrame({"A": pd.array(["a", pd.NA, "b"], dtype=dtype)})
    expected = "      A\n0     a\n1  <NA>\n2     b"
    assert repr(df) == expected

    expected = f"0       a\n1    <NA>\n2       b\nName: A, dtype: {dtype}"
    assert repr(df.A) == expected

    arr_name = "ArrowStringArray" if dtype == "arrow_string" else "StringArray"
    expected = f"<{arr_name}>\n['a', <NA>, 'b']\nLength: 3, dtype: {dtype}"
    assert repr(df.A.array) == expected


def test_none_to_nan(cls):
    a = cls._from_sequence(["a", None, "b"])
    assert a[1] is not None
    assert a[1] is pd.NA


def test_setitem_validates(cls):
    arr = cls._from_sequence(["a", "b"])

    if cls is pd.arrays.StringArray:
{'fraction_non_alphanumeric': 0.1338235294117647, 'fraction_numerical': 0.010294117647058823, 'mean_word_length': 3.0877403846153846, 'pattern_counts': {'":': 5, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6635256', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1239, 'n_words': 272}