@@ -582,7 +582,10 @@ def test_types_quantile() -> None:
582582
583583
584584def test_types_clip () -> None :
585+ """Test different overloads of Series.clip GH984."""
585586 s = pd .Series ([- 10 , 2 , 3 , 10 ])
587+ lower = pd .Series ([- 10 , - 10 , - 3 , - 10 ])
588+ upper = pd .Series ([50 , 52 , 53 , 51 ])
586589 check (
587590 assert_type (s .clip (lower = None , upper = None ), "pd.Series[int]" ),
588591 pd .Series ,
@@ -608,10 +611,101 @@ def test_types_clip() -> None:
608611 )
609612 check (assert_type (s .clip (lower = 0 , upper = 5 , inplace = True ), None ), type (None ))
610613 check (assert_type (s .clip (lower = 0 , upper = None , inplace = True ), None ), type (None ))
614+ check (
615+ assert_type (s .clip (lower = None , upper = None , inplace = True ), "pd.Series[int]" ),
616+ pd .Series ,
617+ np .integer ,
618+ )
611619 check (
612620 assert_type (s .clip (lower = None , upper = 5 , inplace = True ), None ),
613621 type (None ),
614622 )
623+ check (
624+ assert_type (s .clip (lower = lower , upper = upper ), "pd.Series[int]" ),
625+ pd .Series ,
626+ np .integer ,
627+ )
628+ check (
629+ assert_type (s .clip (lower = lower , upper = upper , axis = 0 ), "pd.Series[int]" ),
630+ pd .Series ,
631+ np .integer ,
632+ )
633+ check (
634+ assert_type (s .clip (lower = lower , upper = upper , axis = "index" ), "pd.Series[int]" ),
635+ pd .Series ,
636+ np .integer ,
637+ )
638+ check (assert_type (s .clip (lower = lower , upper = upper , inplace = True ), None ), type (None ))
639+ check (
640+ assert_type (s .clip (lower = lower , upper = upper , axis = 0 , inplace = True ), None ),
641+ type (None ),
642+ )
643+ check (
644+ assert_type (s .clip (lower = lower , upper = upper , axis = "index" , inplace = True ), None ),
645+ type (None ),
646+ )
647+
648+ # without lower
649+ check (assert_type (s .clip (upper = None ), "pd.Series[int]" ), pd .Series , np .integer )
650+ check (assert_type (s .clip (upper = 5 ), "pd.Series[int]" ), pd .Series , np .integer )
651+ check (
652+ assert_type (s .clip (upper = None , inplace = True ), "pd.Series[int]" ),
653+ pd .Series ,
654+ np .integer ,
655+ )
656+ check (assert_type (s .clip (upper = 5 , inplace = True ), None ), type (None ))
657+ check (assert_type (s .clip (upper = upper ), "pd.Series[int]" ), pd .Series , np .integer )
658+ check (
659+ assert_type (s .clip (upper = upper , axis = 0 ), "pd.Series[int]" ),
660+ pd .Series ,
661+ np .integer ,
662+ )
663+ check (
664+ assert_type (s .clip (upper = upper , axis = "index" ), "pd.Series[int]" ),
665+ pd .Series ,
666+ np .integer ,
667+ )
668+ check (assert_type (s .clip (upper = upper , inplace = True ), None ), type (None ))
669+ check (assert_type (s .clip (upper = upper , axis = 0 , inplace = True ), None ), type (None ))
670+ check (
671+ assert_type (s .clip (upper = upper , axis = "index" , inplace = True ), None ), type (None )
672+ )
673+
674+ # without upper
675+ check (assert_type (s .clip (lower = None ), "pd.Series[int]" ), pd .Series , np .integer )
676+ check (assert_type (s .clip (lower = 0 ), "pd.Series[int]" ), pd .Series , np .integer )
677+ check (assert_type (s .clip (lower = None ), "pd.Series[int]" ), pd .Series , np .integer )
678+ check (
679+ assert_type (s .clip (lower = None , inplace = True ), "pd.Series[int]" ),
680+ pd .Series ,
681+ np .integer ,
682+ )
683+ check (assert_type (s .clip (lower = 0 , inplace = True ), None ), type (None ))
684+ check (
685+ assert_type (s .clip (lower = None , inplace = True ), "pd.Series[int]" ),
686+ pd .Series ,
687+ np .integer ,
688+ )
689+ check (assert_type (s .clip (lower = lower ), "pd.Series[int]" ), pd .Series , np .integer )
690+ check (
691+ assert_type (s .clip (lower = lower , axis = 0 ), "pd.Series[int]" ),
692+ pd .Series ,
693+ np .integer ,
694+ )
695+ check (
696+ assert_type (s .clip (lower = lower , axis = "index" ), "pd.Series[int]" ),
697+ pd .Series ,
698+ np .integer ,
699+ )
700+ check (assert_type (s .clip (lower = lower , inplace = True ), None ), type (None ))
701+ check (assert_type (s .clip (lower = lower , axis = 0 , inplace = True ), None ), type (None ))
702+ check (
703+ assert_type (s .clip (lower = lower , axis = "index" , inplace = True ), None ), type (None )
704+ )
705+
706+ if TYPE_CHECKING_INVALID_USAGE :
707+ s .clip (lower = lower , axis = 1 ) # type: ignore[call-overload] # pyright: ignore[reportArgumentType]
708+ s .clip (lower = lower , axis = "column" ) # type: ignore[call-overload] # pyright: ignore[reportArgumentType]
615709
616710
617711def test_types_abs () -> None :
0 commit comments