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

z-score warning #191

Closed
jgallowa07 opened this issue Nov 6, 2024 · 0 comments
Closed

z-score warning #191

jgallowa07 opened this issue Nov 6, 2024 · 0 comments

Comments

@jgallowa07
Copy link
Member

I don't know if I would consider this a "bug", but whenever I run zscore I get

/home/jared/MatsenGroup/Projects/phippery/phippery/phippery/zscore.py:125: RuntimeWarning: invalid value encountered in divide
  zs = (data - null_means) / null_stds
/home/jared/MatsenGroup/Projects/phippery/phippery/phippery/zscore.py:125: RuntimeWarning: divide by zero encountered in divide
  zs = (data - null_means) / null_stds

I've tried doing a safer divide strategy by replacing this chunk with:

        else:
            data = data_df.loc[pid].to_numpy()
            null_means = means_df.loc[ibin].to_numpy()
            null_stds = stds_df.loc[ibin].to_numpy()
            # Replace invalid values in null_stds with NaN
            null_stds = np.where(
                np.isfinite(null_stds) & (null_stds != 0), null_stds, np.nan
            )

            # Compute zs safely; np.nan_to_num replaces NaNs with 0 in the result
            zs = np.nan_to_num((data - null_means) / null_stds, nan=0.0)

        assert zs.dtype == np.float64
        zscore_df.loc[pid] = zs

    return zscore_df, means_df, stds_df

but for some strange reason the enrichment table comes out as an object datatype in the xarray object. This isn't really problem so instead I'll just be adding a warning catch to #189

jgallowa07 pushed a commit that referenced this issue Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant