Streamlit does not deploy SciPy

Summary

I am trying to code code a simple algorithm which can identify the type of the distribution of the given data set. To accomplish that, I used scipy.stats.goodness_of_fit. It works without using/launching streamlit in my script. However, when it comes to using with streamlit in the same code, it generates the following error. I shared my code below. And note that, all the versions of the libraries that I have been using are updated already along with python.

Steps to reproduce

Code snippet:

class Statistics:
    @staticmethod
    def execute(data):
        data.fillna(value=0, method=None, inplace=True)
        por = data["Porosity"]

        rng = np.random.default_rng()
        pseudo_data = stats.uniform.rvs(size=len(por), random_state=rng)
        known_params = {
            'loc': por.mean(),
            'scale': por.std()
        }

        res = stats.goodness_of_fit(stats.norm, pseudo_data, known_params=known_params,
                                    statistic='ks', random_state=rng)

        return res.pvalue

file = st.file_uploader(label="Upload Your Data File", accept_multiple_files=False, type=["csv", "xlsx", "json"])
file_name = file.__str__()

if ".csv" in file_name:
    pass

elif ".xlsx" in file_name:
    file_dataFrame = pd.read_excel(file, sheet_name="Sheet1")
    phi = Statistics()
    st.write(phi.execute(file_dataFrame))

Make sure you install scipy>=1.10.

2 Likes

I think you have not reade my description well. Because, I already had mentioned that all the librariers are in their latest versions.

I have, but the error message suggests otherwise and mistakes happen.
You can check the version right before calling goodness_of_fit().

import scipy
st.info(f"SciPy version: {scipy.__version__}")
res = stats.goodness_of_fit(stats.norm, pseudo_data, known_params=known_params,
                                    statistic='ks', random_state=rng)
1 Like

Wow, it showed that I have been using version 1.8.1. Interesting since I had upgraded all the libraries. Finally, I upgraded one more time using the pip command; and it worked! Thank you.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.