MCPcopy
hub / github.com/dask/dask / test_string_accessor

Function test_string_accessor

dask/dataframe/dask_expr/tests/test_string_accessor.py:77–114  ·  view source on GitHub ↗
(ser, dser, func, kwargs)

Source from the content-addressed store, hash-verified

75 ],
76)
77def test_string_accessor(ser, dser, func, kwargs):
78 if pyarrow_strings_enabled():
79 ser = ser.astype("string[pyarrow]")
80
81 assert_eq(getattr(ser.str, func)(**kwargs), getattr(dser.str, func)(**kwargs))
82
83 if func in (
84 "contains",
85 "endswith",
86 "fullmatch",
87 "isalnum",
88 "isalpha",
89 "isdecimal",
90 "isdigit",
91 "islower",
92 "isspace",
93 "istitle",
94 "isupper",
95 "startswith",
96 "match",
97 ):
98 # This returns arrays and doesn't work in dask/dask either
99 return
100
101 ser.index = ser.values
102 ser = ser.sort_index()
103 dser = from_pandas(ser, npartitions=3)
104 pdf_result = getattr(ser.index.str, func)(**kwargs)
105
106 if func == "cat" and len(kwargs) > 0:
107 # Doesn't work with others on Index
108 return
109 if isinstance(pdf_result, pd.DataFrame):
110 assert_eq(
111 getattr(dser.index.str, func)(**kwargs), pdf_result, check_index=False
112 )
113 else:
114 assert_eq(getattr(dser.index.str, func)(**kwargs), pdf_result)
115
116
117def test_str_accessor_cat(ser, dser):

Callers

nothing calls this directly

Calls 4

pyarrow_strings_enabledFunction · 0.90
assert_eqFunction · 0.90
from_pandasFunction · 0.90
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…