MCPcopy
hub / github.com/pydata/xarray / test_case_str

Function test_case_str

xarray/tests/test_accessor_str.py:279–330  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

277
278
279def test_case_str() -> None:
280 # This string includes some unicode characters
281 # that are common case management corner cases
282 value = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi⁵Å Ç Ⅰ"]).astype(np.str_)
283
284 exp_capitalized = xr.DataArray(["Some word dž ß ᾓ σς ffi⁵å ç ⅰ"]).astype(np.str_)
285 exp_lowered = xr.DataArray(["some word dž ß ᾓ σς ffi⁵å ç ⅰ"]).astype(np.str_)
286 exp_swapped = xr.DataArray(["soME WoRD dž SS ᾛ σς FFI⁵å ç ⅰ"]).astype(np.str_)
287 exp_titled = xr.DataArray(["Some Word Dž Ss ᾛ Σς Ffi⁵Å Ç Ⅰ"]).astype(np.str_)
288 exp_uppered = xr.DataArray(["SOME WORD DŽ SS ἫΙ ΣΣ FFI⁵Å Ç Ⅰ"]).astype(np.str_)
289 exp_casefolded = xr.DataArray(["some word dž ss ἣι σσ ffi⁵å ç ⅰ"]).astype(np.str_)
290
291 exp_norm_nfc = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi⁵Å Ç Ⅰ"]).astype(np.str_)
292 exp_norm_nfkc = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi5Å Ç I"]).astype(np.str_)
293 exp_norm_nfd = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi⁵Å Ç Ⅰ"]).astype(np.str_)
294 exp_norm_nfkd = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi5Å Ç I"]).astype(np.str_)
295
296 res_capitalized = value.str.capitalize()
297 res_casefolded = value.str.casefold()
298 res_lowered = value.str.lower()
299 res_swapped = value.str.swapcase()
300 res_titled = value.str.title()
301 res_uppered = value.str.upper()
302
303 res_norm_nfc = value.str.normalize("NFC")
304 res_norm_nfd = value.str.normalize("NFD")
305 res_norm_nfkc = value.str.normalize("NFKC")
306 res_norm_nfkd = value.str.normalize("NFKD")
307
308 assert res_capitalized.dtype == exp_capitalized.dtype
309 assert res_casefolded.dtype == exp_casefolded.dtype
310 assert res_lowered.dtype == exp_lowered.dtype
311 assert res_swapped.dtype == exp_swapped.dtype
312 assert res_titled.dtype == exp_titled.dtype
313 assert res_uppered.dtype == exp_uppered.dtype
314
315 assert res_norm_nfc.dtype == exp_norm_nfc.dtype
316 assert res_norm_nfd.dtype == exp_norm_nfd.dtype
317 assert res_norm_nfkc.dtype == exp_norm_nfkc.dtype
318 assert res_norm_nfkd.dtype == exp_norm_nfkd.dtype
319
320 assert_equal(res_capitalized, exp_capitalized)
321 assert_equal(res_casefolded, exp_casefolded)
322 assert_equal(res_lowered, exp_lowered)
323 assert_equal(res_swapped, exp_swapped)
324 assert_equal(res_titled, exp_titled)
325 assert_equal(res_uppered, exp_uppered)
326
327 assert_equal(res_norm_nfc, exp_norm_nfc)
328 assert_equal(res_norm_nfd, exp_norm_nfd)
329 assert_equal(res_norm_nfkc, exp_norm_nfkc)
330 assert_equal(res_norm_nfkd, exp_norm_nfkd)
331
332
333def test_replace(dtype) -> None:

Callers

nothing calls this directly

Calls 9

assert_equalFunction · 0.90
capitalizeMethod · 0.80
casefoldMethod · 0.80
lowerMethod · 0.80
swapcaseMethod · 0.80
titleMethod · 0.80
upperMethod · 0.80
normalizeMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…