@@ -1021,65 +1021,66 @@ def cols_allclose(col1, col2):
10211021 result , pd .DataFrame ({"allclose" : [True , True , True ]}, index = pd .Index ([0 , 1 , 2 ], name = "idx" ))
10221022 )
10231023
1024- def test_reduce_infer_nesting ():
1025- """Test that nesting inference works in reduce"""
1026-
1027- ndf = generate_data (3 , 20 , seed = 1 )
1028-
1029- # Test simple case
1030- def complex_output (flux ):
1031- return {
1032- "max_flux" : np .max (flux ),
1033- "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1034- }
1035-
1036- result = ndf .reduce (complex_output , "nested.flux" )
1037- assert list (result .columns ) == ["max_flux" , "lc" ]
1038- assert list (result .lc .nest .fields ) == ["flux_quantiles" ]
1039-
1040- # Test multi-column nested output
1041- def complex_output (flux ):
1042- return {
1043- "max_flux" : np .max (flux ),
1044- "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1045- "lc.labels" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
1046- }
1047-
1048- result = ndf .reduce (complex_output , "nested.flux" )
1049- assert list (result .columns ) == ["max_flux" , "lc" ]
1050- assert list (result .lc .nest .fields ) == ["flux_quantiles" , "labels" ]
1051-
1052- # Test integer names
1053- def complex_output (flux ):
1054- return np .max (flux ), np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]), [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
1055-
1056- result = ndf .reduce (complex_output , "nested.flux" )
1057- assert list (result .columns ) == [0 , 1 , 2 ]
1058-
1059- # Test multiple nested structures output
1060- def complex_output (flux ):
1061- return {
1062- "max_flux" : np .max (flux ),
1063- "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1064- "lc.labels" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
1065- "meta.colors" : ["green" , "red" , "blue" ],
1066- }
1067-
1068- result = ndf .reduce (complex_output , "nested.flux" )
1069- assert list (result .columns ) == ["max_flux" , "lc" , "meta" ]
1070- assert list (result .lc .nest .fields ) == ["flux_quantiles" , "labels" ]
1071- assert list (result .lc .meta .fields ) == ["colors" ]
1072-
1073- # Test only nested structure output
1074- def complex_output (flux ):
1075- return {
1076- "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1077- "lc.labels" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
1078- }
1079-
1080- result = ndf .reduce (complex_output , "nested.flux" )
1081- assert list (result .columns ) == ["lc" ]
1082- assert list (result .lc .nest .fields ) == ["flux_quantiles" , "labels" ]
1024+
1025+ def test_reduce_infer_nesting ():
1026+ """Test that nesting inference works in reduce"""
1027+
1028+ ndf = generate_data (3 , 20 , seed = 1 )
1029+
1030+ # Test simple case
1031+ def complex_output (flux ):
1032+ return {
1033+ "max_flux" : np .max (flux ),
1034+ "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1035+ }
1036+
1037+ result = ndf .reduce (complex_output , "nested.flux" )
1038+ assert list (result .columns ) == ["max_flux" , "lc" ]
1039+ assert list (result .lc .nest .fields ) == ["flux_quantiles" ]
1040+
1041+ # Test multi-column nested output
1042+ def complex_output (flux ):
1043+ return {
1044+ "max_flux" : np .max (flux ),
1045+ "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1046+ "lc.labels" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
1047+ }
1048+
1049+ result = ndf .reduce (complex_output , "nested.flux" )
1050+ assert list (result .columns ) == ["max_flux" , "lc" ]
1051+ assert list (result .lc .nest .fields ) == ["flux_quantiles" , "labels" ]
1052+
1053+ # Test integer names
1054+ def complex_output (flux ):
1055+ return np .max (flux ), np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]), [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
1056+
1057+ result = ndf .reduce (complex_output , "nested.flux" )
1058+ assert list (result .columns ) == [0 , 1 , 2 ]
1059+
1060+ # Test multiple nested structures output
1061+ def complex_output (flux ):
1062+ return {
1063+ "max_flux" : np .max (flux ),
1064+ "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1065+ "lc.labels" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
1066+ "meta.colors" : ["green" , "red" , "blue" ],
1067+ }
1068+
1069+ result = ndf .reduce (complex_output , "nested.flux" )
1070+ assert list (result .columns ) == ["max_flux" , "lc" , "meta" ]
1071+ assert list (result .lc .nest .fields ) == ["flux_quantiles" , "labels" ]
1072+ assert list (result .meta .nest .fields ) == ["colors" ]
1073+
1074+ # Test only nested structure output
1075+ def complex_output (flux ):
1076+ return {
1077+ "lc.flux_quantiles" : np .quantile (flux , [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]),
1078+ "lc.labels" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
1079+ }
1080+
1081+ result = ndf .reduce (complex_output , "nested.flux" )
1082+ assert list (result .columns ) == ["lc" ]
1083+ assert list (result .lc .nest .fields ) == ["flux_quantiles" , "labels" ]
10831084
10841085
10851086def test_scientific_notation ():
0 commit comments