MCPcopy Create free account
hub / github.com/apache/arrow / test_utf8_zfill

Function test_utf8_zfill

python/pyarrow/tests/test_compute.py:1177–1205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1175
1176
1177def test_utf8_zfill():
1178 assert pc.utf8_zfill is pc.utf8_zero_fill
1179
1180 # match str.zfill behavior
1181 examples = ['A', 'AB', 'ABC', '', '-1', '+1', '1', None]
1182 for width in range(0, 6):
1183 arr = pa.array(examples)
1184 result = pc.utf8_zero_fill(arr, width=width).to_pylist()
1185 expected = [x.zfill(width) if x is not None else None for x in examples]
1186 assert result == expected, f"Mismatch at width={width}: {result} vs {expected}"
1187
1188 # unicode padding character
1189 arr = pa.array(["1", "-2", "+3"])
1190 result = pc.utf8_zero_fill(arr, options=pc.ZeroFillOptions(
1191 width=5, padding="💠")).to_pylist()
1192 assert result == ["💠💠💠💠1", "-💠💠💠2", "+💠💠💠3"]
1193
1194 # custom ASCII padding character
1195 arr = pa.array(["1", "-2", "+3"])
1196 result = pc.utf8_zero_fill(arr, options=pc.ZeroFillOptions(
1197 width=4, padding="x")).to_pylist()
1198 assert result == ["xxx1", "-xx2", "+xx3"]
1199
1200 # multi-codepoint padding — should raise
1201 arr = pa.array(["foo"])
1202 with pytest.raises(pa.ArrowInvalid, match="Padding must be one codepoint"):
1203 pc.utf8_zero_fill(arr, options=pc.ZeroFillOptions(width=4, padding="spam"))
1204 with pytest.raises(pa.ArrowInvalid, match="Padding must be one codepoint"):
1205 pc.utf8_zero_fill(arr, options=pc.ZeroFillOptions(width=4, padding=""))
1206
1207
1208@pytest.mark.pandas

Callers

nothing calls this directly

Calls 2

ZeroFillOptionsMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected