Describe the bug
minmax_scaling silently returns NaN for any column where all values are identical (constant column). No error is raised — only a low-level NumPy RuntimeWarning: invalid value encountered in divide is emitted, which is easy to miss. The function computes 0 / 0 internally and writes NaN into the output without informing the user.
Notably, the sibling function standardize() in the same file already handles this edge case correctly (it sets constant columns to 0.0), but minmax_scaling does not.
Steps/Code to Reproduce
import numpy as np
from mlxtend.preprocessing import minmax_scaling
# Column 0 is constant (all 5s), Column 1 is normal
ary = np.array([[5, 1],
[5, 2],
[5, 3]])
result = minmax_scaling(ary, columns=[0, 1])
print(result)
Expected Results
Constant columns should either:
- be set to
0.0 (like standardize() does), or
- raise a clear
ValueError explaining that the column has zero range.
[[0. 0. ]
[0. 0.5]
[0. 1. ]]
Actual Results
Column 0 is silently filled with NaN:
[[nan 0. ]
[nan 0.5]
[nan 1. ]]
RuntimeWarning: invalid value encountered in divide
Versions
MLxtend 0.23.4
Windows-11-10.0.26200-SP0
Python 3.13.5 (tags/v3.13.5:6cb20a2, Jun 11 2025, 16:15:46) [MSC v.1943 64 bit (AMD64)]
Scikit-learn 1.7.0
NumPy 2.2.1
SciPy 1.15.2
Describe the bug
minmax_scalingsilently returnsNaNfor any column where all values are identical (constant column). No error is raised — only a low-level NumPyRuntimeWarning: invalid value encountered in divideis emitted, which is easy to miss. The function computes0 / 0internally and writesNaNinto the output without informing the user.Notably, the sibling function
standardize()in the same file already handles this edge case correctly (it sets constant columns to0.0), butminmax_scalingdoes not.Steps/Code to Reproduce
Expected Results
Constant columns should either:
0.0(likestandardize()does), orValueErrorexplaining that the column has zero range.Actual Results
Column 0 is silently filled with
NaN:Versions