Skip to content

[Data] StandardScaler.transform() cannot handle non-NAN columns when StandardScaler.stats_ is NAN for that column #51243

Closed

Description

@jpatra72

What happened + What you expected to happen

StandardScaler.transform() should ideally return NAN for columns which have StandardScaler.stats_ as None. But the current implementation leads to -

TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

Versions / Dependencies

Reproduction script

import pandas as pd
import ray
from ray.data.preprocessors import StandardScaler


df_sample = pd.DataFrame({'A': [-1, 0], 'B': [None, None]})

ds_sample = ray.data.from_pandas(df_sample)
pp = StandardScaler(columns=['A', 'B'])
pp = pp.fit(ds_sample)

# `None` mean/std for C.
print(f"preprocessor stats: {pp.stats_}")


df_transform = pd.DataFrame({'A': [0, 0], 'B': [0, None]})

ds_transform = ray.data.from_pandas(df_transform)
print(pp.transform(ds_transform).show()) # Errors

Issue Severity

High: It blocks me from completing my task.

Activity

  1. added
    bug
    triage
    on Mar 11, 2025
  2. added
    data
    on Mar 11, 2025
  3. added
    P1
    and removed
    triage
    on Mar 11, 2025
  4. added a commit that references this issue on Mar 12, 2025
    a62e4a0
  5. added a commit that references this issue on Mar 13, 2025
    8ade583
  6. added a commit that references this issue on Mar 18, 2025
    49c5c17
  7. added a commit that references this issue on Mar 27, 2025
    bcdd2a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1bugcommunity-backlogdata

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions