fbdesignpro / sweetviz

Visualize and compare datasets, target values and associations, with one line of code.
MIT License
2.9k stars 273 forks source link

AttributeError: module 'numpy' has no attribute 'warnings' #150

Closed SIVASHANKAR-S closed 1 year ago

SIVASHANKAR-S commented 1 year ago

Code to reproduce


import sweetviz as sv
import pandas as pd

irsi = pd.read_csv("iris_data.csv")
my_report = sv.analyze(irsi)
my_report.show_html()

Error Message

AttributeError                            Traceback (most recent call last)
Cell In[2], line 6
      2 import pandas as pd
      5 irsi = pd.read_csv("iris_data.csv")
----> 6 my_report = sv.analyze(irsi)
      7 my_report.show_html()

File [c:\Users\xxx\anaconda3\Lib\site-packages\sweetviz\sv_public.py:12](file:///C:/Users/iitsi/anaconda3/Lib/site-packages/sweetviz/sv_public.py:12), in analyze(source, target_feat, feat_cfg, pairwise_analysis)
      8 def analyze(source: Union[pd.DataFrame, Tuple[pd.DataFrame, str]],
      9             target_feat: str = None,
     10             feat_cfg: FeatureConfig = None,
     11             pairwise_analysis: str = 'auto'):
---> 12     report = sweetviz.DataframeReport(source, target_feat, None,
     13                                       pairwise_analysis, feat_cfg)
     14     return report

File [c:\Users\xxxx\anaconda3\Lib\site-packages\sweetviz\dataframe_report.py:256](file:///C:/Users/iitsi/anaconda3/Lib/site-packages/sweetviz/dataframe_report.py:256), in DataframeReport.__init__(self, source, target_feature_name, compare, pairwise_analysis, fc)
    253 for f in features_to_process:
    254     # start = time.perf_counter()
    255     self.progress_bar.set_description_str(f"Feature: {f.source.name}")
--> 256     self._features[f.source.name] = sa.analyze_feature_to_dictionary(f)
    257     self.progress_bar.update(1)
    258     # print(f"DONE FEATURE------> {f.source.name}"
    259     #       f" {(time.perf_counter() - start):.2f}   {self._features[f.source.name]['type']}")
...
    318     return Tester
--> 320 raise AttributeError("module {!r} has no attribute "
    321                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'warnings'
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?e4149714-5e91-4f3d-852e-18654fd7de5b) or open in a [text editor](command:workbench.action.openLargeOutput?e4149714-5e91-4f3d-852e-18654fd7de5b). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...

Version Using :

numpy == 1.24.3
sweetviz==2.1.4
SIVASHANKAR-S commented 1 year ago

I tried below pull. Unfortunately It throwing the same error.

" You can avoid having to downgrade numpy with this fix: https://github.com/fbdesignpro/sweetviz/pull/131#issuecomment-1401394461"

Punya227 commented 1 year ago

did your problem solved ?

anamabo commented 1 year ago

I'm experiencing the same problem.

Versions of my environment

numpy==1.25.2 sweetviz ==2.1.4

Python 3.9

anamabo commented 1 year ago

@SIVASHANKAR-S : I solved the problem installing numpy==1.23.1

I suggest updating the dependencies of sweetviz such that this package can run with Pandas >=2.0.3 and numpy>=1.25.2

mingjun1120 commented 1 year ago

@SIVASHANKAR-S : I solved the problem installing numpy==1.23.1

I suggest updating the dependencies of sweetviz such that this package can run with Pandas >=2.0.3 and numpy>=1.25.2

@fbdesignpro I agree with this suggestion as I was also facing this issue yesterday and I had created a #153 issue. However, there is a small issue with the Target Analysis feature in sweetviz==2.1.4, as it no longer supports string data types as target values. For instance, in the Titanic dataset, Survived and Not Survived are in string format, which is not supported in the current version. This feature was supported in sweetviz==2.1.3. The latest version of sweetviz now requires users to convert the unique values of the target feature to numbers before it can work. For instance, change Survived and Not Survived to 1 and 0.

fbdesignpro commented 1 year ago

@mingjun1120 Thank you for the feedback, thanks to a new contributor we will be releasing an updated version that will fix the issue mentioned in this thread.

I AM curious about what you mentioned regarding the target analysis. I don't think categorical (string) target analysis support was removed in 2.1.4. If you can, would you be able to verify the previous behavior in 2.1.3? IIRC target analysis was always limited to numerical or boolean. Thanks again!!

fbdesignpro commented 1 year ago

Thanks again for reporting this, should be fixed with the latest version 2.2.1! Please let us know if you run into anything else with the latest version.

T-Rocky commented 1 year ago

Hello, i updated sweetviz to version 2.2.1 and the same error "module 'numpy' has no attribute 'warnings'" is shown when trying to sv.analyze

fbdesignpro commented 1 year ago

@T-Rocky I'm sorry to hear it! I looked at the code base which SHOULD be out there for 2.2.1, and there is no instance of any use of "np. warnings" that I can find, only the "warnings" module by itself. (although I might have missed something!)

If that is the one you have been using, the pip "upgrade" command has given us issues in the past, as mentioned in the readme. Can you try uninstalling and reinstalling the package, to see if it fixes it? If not, I'll have to double check what we published!

T-Rocky commented 1 year ago

Okay, will try to uninstall and install. Should I be using a specific version of numpy or it should work with any? thanks!

T-Rocky commented 1 year ago

I uninstalled and installed sweetviz 2.2.1 and i am still getting the error. Here is a snippet of the error, where I can see "np.warnings" being used

File ~/Desktop/Xepelin/LNE012023/.lne_venv/lib/python3.11/site-packages/sweetviz/graph_numeric.py:70, in GraphNumeric.init(self, which_graph, to_process) 66 normalizing_weights = norm_source 68 gap_percent = config["Graphs"].getfloat("summary_graph_categorical_gap") ---> 70 np.warnings.filterwarnings('ignore', category=np.VisibleDeprecationWarning) 71 self.hist_specs = axs.hist(plot_data, weights = normalizing_weights, bins=self.num_bins, \ 72 rwidth = (100.0 - gap_percent) / 100.0) 73 np.warnings.filterwarnings('once', category=np.VisibleDeprecationWarning)

fbdesignpro commented 1 year ago

@T-Rocky mmm strange. "np.warnings" is no longer in the code in Git, the release, or pypi. This is what I get looking at the code in Git for example:

image

Notice line 70 has no "np." before "warnings". Not sure if this is a distribution or upgrade issue?

T-Rocky commented 1 year ago

Yes I realized the same when looking at the code. I do have version 2.2.1 on my computer, so I believe the version is not reflecting the latest code on git

fbdesignpro commented 1 year ago

@T-Rocky I just did a clean install using pip install sweetviz and the code looks correct. What kind of system are you using for install? Is it through Anaconda or some other system? (Never ran into this, trying to figure it out!) thank you!

frank1010111 commented 1 year ago

The new sweetviz version works for me as well. My best guess is that you have a virtual environment with version 2.1 that is throwing the error and a different environment with version 2.2 that would work if it were being imported.