@@ -2978,23 +2978,23 @@ def test_pandas_polars_profile_histogram(dxf: DataExplorerFixture):
2978
2978
(
2979
2979
_get_histogram (5 , method = "sturges" ),
2980
2980
{
2981
- "bin_edges" : ["0.5000 " , "1.50 " ],
2981
+ "bin_edges" : ["1.00 " , "1.00 " ],
2982
2982
"bin_counts" : [11 ],
2983
2983
"quantiles" : [],
2984
2984
},
2985
2985
),
2986
2986
(
2987
2987
_get_histogram (5 , method = "freedman_diaconis" ),
2988
2988
{
2989
- "bin_edges" : ["0.5000 " , "1.50 " ],
2989
+ "bin_edges" : ["1.00 " , "1.00 " ],
2990
2990
"bin_counts" : [11 ],
2991
2991
"quantiles" : [],
2992
2992
},
2993
2993
),
2994
2994
(
2995
2995
_get_histogram (5 , method = "scott" ),
2996
2996
{
2997
- "bin_edges" : ["0.5000 " , "1.50 " ],
2997
+ "bin_edges" : ["1.00 " , "1.00 " ],
2998
2998
"bin_counts" : [11 ],
2999
2999
"quantiles" : [],
3000
3000
},
@@ -3101,6 +3101,46 @@ def test_profile_histogram_windows_int32_bug():
3101
3101
assert (result == expected ).all ()
3102
3102
3103
3103
3104
+ def test_histogram_single_value_special_case ():
3105
+ # Test the special case where all values are the same
3106
+ from ..data_explorer import _get_histogram_numpy
3107
+
3108
+ # Test with integer array of all same values
3109
+ arr_int = np .array ([5 , 5 , 5 , 5 , 5 ])
3110
+ bin_counts , bin_edges = _get_histogram_numpy (arr_int , 10 , method = "sturges" )
3111
+ assert len (bin_counts ) == 1
3112
+ assert bin_counts [0 ] == 5
3113
+ assert len (bin_edges ) == 2
3114
+ assert bin_edges [0 ] == 5
3115
+ assert bin_edges [1 ] == 5
3116
+
3117
+ # Test with float array of all same values
3118
+ arr_float = np .array ([3.14 , 3.14 , 3.14 , 3.14 ])
3119
+ bin_counts , bin_edges = _get_histogram_numpy (arr_float , 10 , method = "fd" )
3120
+ assert len (bin_counts ) == 1
3121
+ assert bin_counts [0 ] == 4
3122
+ assert len (bin_edges ) == 2
3123
+ assert bin_edges [0 ] == 3.14
3124
+ assert bin_edges [1 ] == 3.14
3125
+
3126
+ # Test with single value
3127
+ arr_single = np .array ([42 ])
3128
+ bin_counts , bin_edges = _get_histogram_numpy (arr_single , 10 , method = "scott" )
3129
+ assert len (bin_counts ) == 1
3130
+ assert bin_counts [0 ] == 1
3131
+ assert len (bin_edges ) == 2
3132
+ assert bin_edges [0 ] == 42
3133
+ assert bin_edges [1 ] == 42
3134
+
3135
+ # Test that non-uniform data still works normally
3136
+ arr_mixed = np .array ([1 , 2 , 3 , 4 , 5 ])
3137
+ bin_counts , bin_edges = _get_histogram_numpy (arr_mixed , 5 , method = "fixed" )
3138
+ assert len (bin_counts ) == 5
3139
+ assert len (bin_edges ) == 6
3140
+ # Should not have same start and end edges for non-uniform data
3141
+ assert bin_edges [0 ] != bin_edges [- 1 ]
3142
+
3143
+
3104
3144
# ----------------------------------------------------------------------
3105
3145
# polars backend functionality tests
3106
3146
0 commit comments