Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Stats compute perf #449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions torch_frame/data/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,25 @@ def compute(
sep: str | None = None,
) -> Any:
if self == StatType.MEAN:
flattened = np.hstack(np.hstack(ser.values))
val = np.hstack(ser.values) if ser.values.ndim > 1 else ser.values
flattened = np.hstack(val) if val.ndim > 1 else val
Comment on lines +88 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the chagne doesn't take account of the sequence_numerical case:

self = <StatType.MEAN: 'MEAN'>
ser = 0                                                 [nan]
1         [0.3309801272693331, nan, 0.3018088119575514]
2     ...42, nan, 0.9997390177887806, ...
19                            [nan, 0.36[1182](https://github.com/pyg-team/pytorch-frame/pull/449/checks#step:6:1183)4486676457]
Name: seq_num_1, dtype: object
sep = None

    def compute(
        self,
        ser: Series,
        sep: str | None = None,
    ) -> Any:
        if self == StatType.MEAN:
            val = np.hstack(ser.values) if ser.values.ndim > 1 else ser.values
            flattened = np.hstack(val) if val.ndim > 1 else val
>           finite_mask = np.isfinite(flattened)
E           TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

torch_frame/data/stats.py:90: TypeError

https://github.com/pyg-team/pytorch-frame/actions/runs/12376953024/job/34545299882

finite_mask = np.isfinite(flattened)
if not finite_mask.any():
# NOTE: We may just error out here if eveything is NaN
return np.nan
return np.mean(flattened[finite_mask]).item()

elif self == StatType.STD:
flattened = np.hstack(np.hstack(ser.values))
val = np.hstack(ser.values) if ser.values.ndim > 1 else ser.values
flattened = np.hstack(val) if val.ndim > 1 else val
finite_mask = np.isfinite(flattened)
if not finite_mask.any():
return np.nan
return np.std(flattened[finite_mask]).item()

elif self == StatType.QUANTILES:
flattened = np.hstack(np.hstack(ser.values))
val = np.hstack(ser.values) if ser.values.ndim > 1 else ser.values
flattened = np.hstack(val) if val.ndim > 1 else val
finite_mask = np.isfinite(flattened)
if not finite_mask.any():
return [np.nan, np.nan, np.nan, np.nan, np.nan]
Expand Down
Loading