@@ -778,157 +778,3 @@ def test_groupby_resample_on_column_when_index_is_unusual(df):
778778 expected = DataFrame ({"numbers" : [100 , 200 ]}, index = index )
779779
780780 tm .assert_frame_equal (result , expected )
781-
782-
783- def test_groupby_resample_then_groupby_is_reused_when_index_is_out_of_order ():
784- # GH 59350
785- df = DataFrame (
786- data = {
787- "datetime" : [
788- pd .to_datetime ("2024-07-30T00:00Z" ),
789- pd .to_datetime ("2024-07-30T00:01Z" ),
790- ],
791- "group" : ["A" , "A" ],
792- "numbers" : [100 , 200 ],
793- },
794- index = [1 , 0 ],
795- )
796-
797- gb = df .groupby ("group" )
798-
799- # use gb
800- result_1 = gb [["numbers" ]].transform ("sum" )
801-
802- index = Index ([1 , 0 ])
803- expected = DataFrame ({"numbers" : [300 , 300 ]}, index = index )
804-
805- tm .assert_frame_equal (result_1 , expected )
806-
807- # resample gb, unrelated to above
808- rs = gb .resample ("1min" , on = "datetime" )
809- result_2 = rs .aggregate ({"numbers" : "sum" })
810-
811- index = pd .MultiIndex .from_arrays (
812- [
813- ["A" , "A" ],
814- [pd .to_datetime ("2024-07-30T00:00Z" ), pd .to_datetime ("2024-07-30T00:01Z" )],
815- ],
816- names = [
817- "group" ,
818- "datetime" ,
819- ],
820- )
821- expected = DataFrame ({"numbers" : [100 , 200 ]}, index = index )
822-
823- tm .assert_frame_equal (result_2 , expected )
824-
825- # reuse gb, unrelated to above
826- result_3 = gb [["numbers" ]].transform ("sum" )
827-
828- tm .assert_frame_equal (result_1 , result_3 )
829-
830-
831- def test_groupby_resample_then_groupby_is_reused_when_index_is_set_from_column ():
832- # GH 59350
833- df = DataFrame (
834- data = {
835- "datetime" : [
836- pd .to_datetime ("2024-07-30T00:00Z" ),
837- pd .to_datetime ("2024-07-30T00:01Z" ),
838- ],
839- "group" : ["A" , "A" ],
840- "numbers" : [100 , 200 ],
841- },
842- ).set_index ("group" )
843-
844- gb = df .groupby ("group" )
845-
846- # use gb
847- result_1 = gb [["numbers" ]].transform ("sum" )
848-
849- index = Index (["A" , "A" ], name = "group" )
850- expected = DataFrame ({"numbers" : [300 , 300 ]}, index = index )
851-
852- tm .assert_frame_equal (result_1 , expected )
853-
854- # resample gb, unrelated to above
855- rs = gb .resample ("1min" , on = "datetime" )
856- result_2 = rs .aggregate ({"numbers" : "sum" })
857-
858- index = pd .MultiIndex .from_arrays (
859- [
860- ["A" , "A" ],
861- [pd .to_datetime ("2024-07-30T00:00Z" ), pd .to_datetime ("2024-07-30T00:01Z" )],
862- ],
863- names = [
864- "group" ,
865- "datetime" ,
866- ],
867- )
868- expected = DataFrame ({"numbers" : [100 , 200 ]}, index = index )
869-
870- tm .assert_frame_equal (result_2 , expected )
871-
872- # reuse gb, unrelated to above
873- result_3 = gb [["numbers" ]].transform ("sum" )
874-
875- tm .assert_frame_equal (result_1 , result_3 )
876-
877-
878- def test_groupby_resample_then_groupby_is_reused_when_groupby_selection_is_not_none ():
879- # GH 59350
880- df = DataFrame (
881- data = {
882- "datetime" : [
883- pd .to_datetime ("2024-07-30T00:00Z" ),
884- pd .to_datetime ("2024-07-30T00:01Z" ),
885- ],
886- "group" : ["A" , "A" ],
887- "numbers" : [100 , 200 ],
888- },
889- index = [1 , 0 ],
890- )
891-
892- gb = df .groupby ("group" )
893- gb = gb [["numbers" , "datetime" ]] # gb._selection is ["numbers", "datetime"]
894-
895- # use gb
896- result_1 = gb .transform ("max" )
897-
898- index = Index ([1 , 0 ])
899- expected = DataFrame (
900- {
901- "numbers" : [200 , 200 ],
902- "datetime" : [
903- pd .to_datetime ("2024-07-30T00:01Z" ),
904- pd .to_datetime ("2024-07-30T00:01Z" ),
905- ],
906- },
907- index = index ,
908- )
909-
910- tm .assert_frame_equal (result_1 , expected )
911-
912- # resample gb, unrelated to above
913- rs = gb .resample ("1min" , on = "datetime" )
914- result_2 = rs .aggregate ({"numbers" : "sum" }) # Enter the `except IndexError:` block
915-
916- index = pd .MultiIndex .from_arrays (
917- [
918- ["A" , "A" ],
919- [pd .to_datetime ("2024-07-30T00:00Z" ), pd .to_datetime ("2024-07-30T00:01Z" )],
920- ],
921- names = [
922- "group" ,
923- "datetime" ,
924- ],
925- )
926- columns = pd .MultiIndex .from_arrays ([["numbers" ], ["numbers" ]])
927- expected = DataFrame ([[100 ], [200 ]], index = index , columns = columns )
928-
929- tm .assert_frame_equal (result_2 , expected )
930-
931- # reuse gb, unrelated to above
932- result_3 = gb .transform ("max" )
933-
934- tm .assert_frame_equal (result_1 , result_3 )
0 commit comments