@@ -335,90 +335,90 @@ def test_split_with_name():
335335 tm .assert_index_equal (res , exp )
336336
337337
338- def test_partition_series ():
338+ def test_partition_series (any_string_dtype ):
339339 # https://github.com/pandas-dev/pandas/issues/23558
340340
341- values = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" , None ])
341+ s = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" , None ], dtype = any_string_dtype )
342342
343- result = values .str .partition ("_" , expand = False )
344- exp = Series (
343+ result = s .str .partition ("_" , expand = False )
344+ expected = Series (
345345 [("a" , "_" , "b_c" ), ("c" , "_" , "d_e" ), np .nan , ("f" , "_" , "g_h" ), None ]
346346 )
347- tm .assert_series_equal (result , exp )
347+ tm .assert_series_equal (result , expected )
348348
349- result = values .str .rpartition ("_" , expand = False )
350- exp = Series (
349+ result = s .str .rpartition ("_" , expand = False )
350+ expected = Series (
351351 [("a_b" , "_" , "c" ), ("c_d" , "_" , "e" ), np .nan , ("f_g" , "_" , "h" ), None ]
352352 )
353- tm .assert_series_equal (result , exp )
353+ tm .assert_series_equal (result , expected )
354354
355355 # more than one char
356- values = Series (["a__b__c" , "c__d__e" , np .nan , "f__g__h" , None ])
357- result = values .str .partition ("__" , expand = False )
358- exp = Series (
356+ s = Series (["a__b__c" , "c__d__e" , np .nan , "f__g__h" , None ])
357+ result = s .str .partition ("__" , expand = False )
358+ expected = Series (
359359 [
360360 ("a" , "__" , "b__c" ),
361361 ("c" , "__" , "d__e" ),
362362 np .nan ,
363363 ("f" , "__" , "g__h" ),
364364 None ,
365- ]
365+ ],
366366 )
367- tm .assert_series_equal (result , exp )
367+ tm .assert_series_equal (result , expected )
368368
369- result = values .str .rpartition ("__" , expand = False )
370- exp = Series (
369+ result = s .str .rpartition ("__" , expand = False )
370+ expected = Series (
371371 [
372372 ("a__b" , "__" , "c" ),
373373 ("c__d" , "__" , "e" ),
374374 np .nan ,
375375 ("f__g" , "__" , "h" ),
376376 None ,
377- ]
377+ ],
378378 )
379- tm .assert_series_equal (result , exp )
379+ tm .assert_series_equal (result , expected )
380380
381381 # None
382- values = Series (["a b c" , "c d e" , np .nan , "f g h" , None ])
383- result = values .str .partition (expand = False )
384- exp = Series (
382+ s = Series (["a b c" , "c d e" , np .nan , "f g h" , None ], dtype = any_string_dtype )
383+ result = s .str .partition (expand = False )
384+ expected = Series (
385385 [("a" , " " , "b c" ), ("c" , " " , "d e" ), np .nan , ("f" , " " , "g h" ), None ]
386386 )
387- tm .assert_series_equal (result , exp )
387+ tm .assert_series_equal (result , expected )
388388
389- result = values .str .rpartition (expand = False )
390- exp = Series (
389+ result = s .str .rpartition (expand = False )
390+ expected = Series (
391391 [("a b" , " " , "c" ), ("c d" , " " , "e" ), np .nan , ("f g" , " " , "h" ), None ]
392392 )
393- tm .assert_series_equal (result , exp )
393+ tm .assert_series_equal (result , expected )
394394
395395 # Not split
396- values = Series (["abc" , "cde" , np .nan , "fgh" , None ])
397- result = values .str .partition ("_" , expand = False )
398- exp = Series ([("abc" , "" , "" ), ("cde" , "" , "" ), np .nan , ("fgh" , "" , "" ), None ])
399- tm .assert_series_equal (result , exp )
396+ s = Series (["abc" , "cde" , np .nan , "fgh" , None ], dtype = any_string_dtype )
397+ result = s .str .partition ("_" , expand = False )
398+ expected = Series ([("abc" , "" , "" ), ("cde" , "" , "" ), np .nan , ("fgh" , "" , "" ), None ])
399+ tm .assert_series_equal (result , expected )
400400
401- result = values .str .rpartition ("_" , expand = False )
402- exp = Series ([("" , "" , "abc" ), ("" , "" , "cde" ), np .nan , ("" , "" , "fgh" ), None ])
403- tm .assert_series_equal (result , exp )
401+ result = s .str .rpartition ("_" , expand = False )
402+ expected = Series ([("" , "" , "abc" ), ("" , "" , "cde" ), np .nan , ("" , "" , "fgh" ), None ])
403+ tm .assert_series_equal (result , expected )
404404
405405 # unicode
406- values = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" ])
406+ s = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" ], dtype = any_string_dtype )
407407
408- result = values .str .partition ("_" , expand = False )
409- exp = Series ([("a" , "_" , "b_c" ), ("c" , "_" , "d_e" ), np .nan , ("f" , "_" , "g_h" )])
410- tm .assert_series_equal (result , exp )
408+ result = s .str .partition ("_" , expand = False )
409+ expected = Series ([("a" , "_" , "b_c" ), ("c" , "_" , "d_e" ), np .nan , ("f" , "_" , "g_h" )])
410+ tm .assert_series_equal (result , expected )
411411
412- result = values .str .rpartition ("_" , expand = False )
413- exp = Series ([("a_b" , "_" , "c" ), ("c_d" , "_" , "e" ), np .nan , ("f_g" , "_" , "h" )])
414- tm .assert_series_equal (result , exp )
412+ result = s .str .rpartition ("_" , expand = False )
413+ expected = Series ([("a_b" , "_" , "c" ), ("c_d" , "_" , "e" ), np .nan , ("f_g" , "_" , "h" )])
414+ tm .assert_series_equal (result , expected )
415415
416416 # compare to standard lib
417- values = Series (["A_B_C" , "B_C_D" , "E_F_G" , "EFGHEF" ])
418- result = values .str .partition ("_" , expand = False ).tolist ()
419- assert result == [v .partition ("_" ) for v in values ]
420- result = values .str .rpartition ("_" , expand = False ).tolist ()
421- assert result == [v .rpartition ("_" ) for v in values ]
417+ s = Series (["A_B_C" , "B_C_D" , "E_F_G" , "EFGHEF" ], dtype = any_string_dtype )
418+ result = s .str .partition ("_" , expand = False ).tolist ()
419+ assert result == [v .partition ("_" ) for v in s ]
420+ result = s .str .rpartition ("_" , expand = False ).tolist ()
421+ assert result == [v .rpartition ("_" ) for v in s ]
422422
423423
424424def test_partition_index ():
@@ -475,88 +475,96 @@ def test_partition_index():
475475 assert result .nlevels == 3
476476
477477
478- def test_partition_to_dataframe ():
478+ def test_partition_to_dataframe (any_string_dtype ):
479479 # https://github.com/pandas-dev/pandas/issues/23558
480480
481- values = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" , None ])
482- result = values .str .partition ("_" )
483- exp = DataFrame (
481+ s = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" , None ], dtype = any_string_dtype )
482+ result = s .str .partition ("_" )
483+ expected = DataFrame (
484484 {
485485 0 : ["a" , "c" , np .nan , "f" , None ],
486486 1 : ["_" , "_" , np .nan , "_" , None ],
487487 2 : ["b_c" , "d_e" , np .nan , "g_h" , None ],
488- }
488+ },
489+ dtype = any_string_dtype ,
489490 )
490- tm .assert_frame_equal (result , exp )
491+ tm .assert_frame_equal (result , expected )
491492
492- result = values .str .rpartition ("_" )
493- exp = DataFrame (
493+ result = s .str .rpartition ("_" )
494+ expected = DataFrame (
494495 {
495496 0 : ["a_b" , "c_d" , np .nan , "f_g" , None ],
496497 1 : ["_" , "_" , np .nan , "_" , None ],
497498 2 : ["c" , "e" , np .nan , "h" , None ],
498- }
499+ },
500+ dtype = any_string_dtype ,
499501 )
500- tm .assert_frame_equal (result , exp )
502+ tm .assert_frame_equal (result , expected )
501503
502- values = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" , None ])
503- result = values .str .partition ("_" , expand = True )
504- exp = DataFrame (
504+ s = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" , None ], dtype = any_string_dtype )
505+ result = s .str .partition ("_" , expand = True )
506+ expected = DataFrame (
505507 {
506508 0 : ["a" , "c" , np .nan , "f" , None ],
507509 1 : ["_" , "_" , np .nan , "_" , None ],
508510 2 : ["b_c" , "d_e" , np .nan , "g_h" , None ],
509- }
511+ },
512+ dtype = any_string_dtype ,
510513 )
511- tm .assert_frame_equal (result , exp )
514+ tm .assert_frame_equal (result , expected )
512515
513- result = values .str .rpartition ("_" , expand = True )
514- exp = DataFrame (
516+ result = s .str .rpartition ("_" , expand = True )
517+ expected = DataFrame (
515518 {
516519 0 : ["a_b" , "c_d" , np .nan , "f_g" , None ],
517520 1 : ["_" , "_" , np .nan , "_" , None ],
518521 2 : ["c" , "e" , np .nan , "h" , None ],
519- }
522+ },
523+ dtype = any_string_dtype ,
520524 )
521- tm .assert_frame_equal (result , exp )
525+ tm .assert_frame_equal (result , expected )
522526
523527
524- def test_partition_with_name ():
528+ def test_partition_with_name (any_string_dtype ):
525529 # GH 12617
526530
527- s = Series (["a,b" , "c,d" ], name = "xxx" )
528- res = s .str .partition ("," )
529- exp = DataFrame ({0 : ["a" , "c" ], 1 : ["," , "," ], 2 : ["b" , "d" ]})
530- tm .assert_frame_equal (res , exp )
531+ s = Series (["a,b" , "c,d" ], name = "xxx" , dtype = any_string_dtype )
532+ result = s .str .partition ("," )
533+ expected = DataFrame (
534+ {0 : ["a" , "c" ], 1 : ["," , "," ], 2 : ["b" , "d" ]}, dtype = any_string_dtype
535+ )
536+ tm .assert_frame_equal (result , expected )
531537
532538 # should preserve name
533- res = s .str .partition ("," , expand = False )
534- exp = Series ([("a" , "," , "b" ), ("c" , "," , "d" )], name = "xxx" )
535- tm .assert_series_equal (res , exp )
539+ result = s .str .partition ("," , expand = False )
540+ expected = Series ([("a" , "," , "b" ), ("c" , "," , "d" )], name = "xxx" )
541+ tm .assert_series_equal (result , expected )
542+
536543
544+ def test_partition_index_with_name ():
537545 idx = Index (["a,b" , "c,d" ], name = "xxx" )
538- res = idx .str .partition ("," )
539- exp = MultiIndex .from_tuples ([("a" , "," , "b" ), ("c" , "," , "d" )])
540- assert res .nlevels == 3
541- tm .assert_index_equal (res , exp )
546+ result = idx .str .partition ("," )
547+ expected = MultiIndex .from_tuples ([("a" , "," , "b" ), ("c" , "," , "d" )])
548+ assert result .nlevels == 3
549+ tm .assert_index_equal (result , expected )
542550
543551 # should preserve name
544- res = idx .str .partition ("," , expand = False )
545- exp = Index (np .array ([("a" , "," , "b" ), ("c" , "," , "d" )]), name = "xxx" )
546- assert res .nlevels == 1
547- tm .assert_index_equal (res , exp )
552+ result = idx .str .partition ("," , expand = False )
553+ expected = Index (np .array ([("a" , "," , "b" ), ("c" , "," , "d" )]), name = "xxx" )
554+ assert result .nlevels == 1
555+ tm .assert_index_equal (result , expected )
548556
549557
550- def test_partition_sep_kwarg ():
558+ def test_partition_sep_kwarg (any_string_dtype ):
551559 # GH 22676; depr kwarg "pat" in favor of "sep"
552- values = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" ])
560+ s = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" ], dtype = any_string_dtype )
553561
554- expected = values .str .partition (sep = "_" )
555- result = values .str .partition ("_" )
562+ expected = s .str .partition (sep = "_" )
563+ result = s .str .partition ("_" )
556564 tm .assert_frame_equal (result , expected )
557565
558- expected = values .str .rpartition (sep = "_" )
559- result = values .str .rpartition ("_" )
566+ expected = s .str .rpartition (sep = "_" )
567+ result = s .str .rpartition ("_" )
560568 tm .assert_frame_equal (result , expected )
561569
562570
0 commit comments