{"record":{"id":"c96402b6b5667fb3","repo":"apache/beam","slug":"max-value-must-be-greater-than-min-value","errorCode":null,"errorMessage":"max_value must be greater than min_value","messagePattern":"max_value must be greater than min_value","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/tft.py","lineNumber":552,"sourceCode":"      name: Optional[str] = None):\n    \"\"\"\n    This function applies a scaling transformation on the given columns\n    of incoming data. The transformation scales the input values to the\n    range [min_value, max_value].\n\n    Args:\n      columns: A list of column names to apply the transformation on.\n      min_value: The minimum value of the output range.\n      max_value: The maximum value of the output range.\n      name: A name for the operation (optional).\n    \"\"\"\n    super().__init__(columns)\n    self.min_value = min_value\n    self.max_value = max_value\n    self.name = name\n\n    if self.max_value <= self.min_value:\n      raise ValueError('max_value must be greater than min_value')\n\n  def apply_transform(\n      self, data: common_types.TensorType,\n      output_column_name: str) -> common_types.TensorType:\n\n    output = tft.scale_by_min_max(\n        x=data, output_min=self.min_value, output_max=self.max_value)\n    return {output_column_name: output}\n\n\n@register_input_dtype(str)\nclass NGrams(TFTOperation):\n  def __init__(\n      self,\n      columns: list[str],\n      split_string_by_delimiter: Optional[str] = None,\n      *,\n      ngram_range: tuple[int, int] = (1, 1),","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/tft.py#L534-L570","documentation":"ScaleMinMax validates its constructor arguments: the max_value used for scaling must be strictly greater than min_value, otherwise tft.scale_by_min_max would be mathematically invalid. __init__ raises a ValueError when max_value <= min_value.","triggerScenarios":"Constructing tft.ScaleMinMax(columns=[...], min_value=a, max_value=b) with b <= a (equal values or inverted order), including default misuse where both are set to the same number.","commonSituations":"Loading min/max from a config where order was flipped, computing bounds from data and getting equal values for constant columns, or typos swapping the arguments.","solutions":["Swap or correct the values so max_value > min_value.","If bounds come from data, add a guard that skips or defaults scaling for constant columns where min == max.","Validate the config values before instantiating the transform."],"exampleFix":"# before\ntft.ScaleMinMax(columns=['x'], min_value=10, max_value=10)\n\n# after\ntft.ScaleMinMax(columns=['x'], min_value=0, max_value=10)","handlingStrategy":"validation","validationCode":"def make_scale_min_max(columns, min_value, max_value):\n    if not max_value > min_value:\n        raise ValueError('max_value must be greater than min_value')\n    return tft.ScaleMinMax(columns=columns, min_value=min_value, max_value=max_value)","typeGuard":"def valid_min_max(min_value, max_value) -> bool:\n    return max_value > min_value","tryCatchPattern":"try:\n    op = tft.ScaleMinMax(columns=['x'], min_value=mn, max_value=mx)\nexcept ValueError as e:\n    if 'max_value must be greater' in str(e):\n        mn, mx = min(mn, mx), max(mn, mx)  # normalize order\n        op = tft.ScaleMinMax(columns=['x'], min_value=mn, max_value=mx)\n    else:\n        raise","preventionTips":["Validate min < max in config-loading code before instantiating transforms.","Sort or normalize bounds when they are computed from data.","Reject constant columns (min == max) or fall back to ScaleToZScore.","Add unit tests for bound-order validation in transform configs."],"tags":["python","apache-beam","tft","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}