I am attempting to generate a data profiling report using the ydata-profiling library in Python. Upon executing the following code:
import ydata_profiling
profile = ydata_profiling.ProfileReport(df_accidentes)
profile.to_file("report.html")
I encounter the following error:
AttributeError: module 'matplotlib.cbook' has no attribute 'mplDeprecation'
Here is the complete traceback
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\ETL+EDA.ipynb Celda 5 line 2
1 profile = ydata_profiling.ProfileReport(df_accidentes)
----> 2 profile.to_file("report.html")
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\typeguard\__init__.py:1033, in typechecked.<locals>.wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\profile_report.py:355, in ProfileReport.to_file(self, output_file, silent)
352 self.config.html.assets_prefix = str(output_file.stem) + "_assets"
353 create_html_assets(self.config, output_file)
--> 355 data = self.to_html()
357 if output_file.suffix != ".html":
358 suffix = output_file.suffix
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\typeguard\__init__.py:1033, in typechecked.<locals>.wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\profile_report.py:470, in ProfileReport.to_html(self)
462 def to_html(self) -> str:
463 """Generate and return complete template as lengthy string
464 for using with frameworks.
465
(...)
468
469 """
--> 470 return self.html
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\typeguard\__init__.py:1033, in typechecked.<locals>.wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\profile_report.py:277, in ProfileReport.html(self)
274 @property
275 def html(self) -> str:
276 if self._html is None:
--> 277 self._html = self._render_html()
278 return self._html
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\typeguard\__init__.py:1033, in typechecked.<locals>.wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\profile_report.py:385, in ProfileReport._render_html(self)
382 def _render_html(self) -> str:
383 from ydata_profiling.report.presentation.flavours import HTMLReport
--> 385 report = self.report
387 with tqdm(
388 total=1, desc="Render HTML", disable=not self.config.progress_bar
389 ) as pbar:
390 html = HTMLReport(copy.deepcopy(report)).render(
391 nav=self.config.html.navbar_show,
392 offline=self.config.html.use_local_assets,
(...)
400 version=self.description_set.package["ydata_profiling_version"],
401 )
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\typeguard\__init__.py:1033, in typechecked.<locals>.wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\profile_report.py:271, in ProfileReport.report(self)
268 @property
269 def report(self) -> Root:
270 if self._report is None:
--> 271 self._report = get_report_structure(self.config, self.description_set)
272 return self._report
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\typeguard\__init__.py:1033, in typechecked.<locals>.wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\profile_report.py:253, in ProfileReport.description_set(self)
250 @property
251 def description_set(self) -> BaseDescription:
252 if self._description_set is None:
--> 253 self._description_set = describe_df(
254 self.config,
255 self.df,
256 self.summarizer,
257 self.typeset,
258 self._sample,
259 )
260 return self._description_set
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\model\describe.py:137, in describe(config, df, summarizer, typeset, sample)
135 missing_map = get_missing_active(config, table_stats)
136 pbar.total += len(missing_map)
--> 137 missing = {
138 name: progress(get_missing_diagram, pbar, f"Missing diagram {name}")(
139 config, df, settings
140 )
141 for name, settings in missing_map.items()
142 }
143 missing = {name: value for name, value in missing.items() if value is not None}
145 # Sample
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\model\describe.py:138, in <dictcomp>(.0)
135 missing_map = get_missing_active(config, table_stats)
136 pbar.total += len(missing_map)
137 missing = {
--> 138 name: progress(get_missing_diagram, pbar, f"Missing diagram {name}")(
139 config, df, settings
140 )
141 for name, settings in missing_map.items()
142 }
143 missing = {name: value for name, value in missing.items() if value is not None}
145 # Sample
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\utils\progress_bar.py:11, in progress.<locals>.inner(*args, **kwargs)
8 @wraps(fn)
9 def inner(*args, **kwargs) -> Any:
10 bar.set_postfix_str(message)
---> 11 ret = fn(*args, **kwargs)
12 bar.update()
13 return ret
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\model\missing.py:112, in get_missing_diagram(config, df, settings)
109 if len(df) == 0:
110 return None
--> 112 result = handle_missing(settings["name"], settings["function"])(config, df)
113 if result is None:
114 return None
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\model\missing.py:88, in handle_missing.<locals>.inner(*args, **kwargs)
78 warnings.warn(
79 f"""There was an attempt to generate the {missing_name} missing values diagrams, but this failed.
80 To hide this warning, disable the calculation
(...)
84 (include the error message: '{error}')"""
85 )
87 try:
---> 88 return fn(*args, *kwargs)
89 except ValueError as e:
90 warn_missing(name, str(e))
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\multimethod\__init__.py:328, in multimethod.__call__(self, *args, **kwargs)
326 func = self[tuple(func(arg) for func, arg in zip(self.type_checkers, args))]
327 try:
--> 328 return func(*args, **kwargs)
329 except TypeError as ex:
330 raise DispatchError(f"Function {func.__code__}") from ex
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\model\pandas\missing_pandas.py:16, in pandas_missing_bar(config, df)
13 @missing_bar.register
14 def pandas_missing_bar(config: Settings, df: pd.DataFrame) -> str:
15 notnull_counts = len(df) - df.isnull().sum()
---> 16 return plot_missing_bar(
17 config,
18 notnull_counts=notnull_counts,
19 nrows=len(df),
20 columns=list(df.columns),
21 )
File ~\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:80, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
78 @wraps(func)
79 def inner(*args, **kwds):
---> 80 with self._recreate_cm():
81 return func(*args, **kwds)
File ~\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:144, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
142 if typ is None:
143 try:
--> 144 next(self.gen)
145 except StopIteration:
146 return False
File c:\Users\Compumar\Documents\Henry\PI_DA\PI_DA\.venv\Lib\site-packages\ydata_profiling\visualisation\context.py:85, in manage_matplotlib_context()
83 deregister_matplotlib_converters() # revert to original unit registries
84 with warnings.catch_warnings():
---> 85 warnings.filterwarnings("ignore", category=matplotlib.cbook.mplDeprecation)
86 matplotlib.rcParams.update(originalRcParams)
AttributeError: module 'matplotlib.cbook' has no attribute 'mplDeprecation'
I have tried looking through the documentation and searching for a solution, but have come up short. Here are the versions of the relevant libraries I am using as per pip list:
- ydata-profiling: 4.5.1
- matplotlib: 3.8.0
Additionally, I am using a virtual environment (venv) for this project, not Conda, as I saw in some other questions.
Has anyone come across this issue before or have any suggestions on how to resolve it? Any help would be greatly appreciated.
I initially suspected that the error might be due to a version mismatch between ydata-profiling and matplotlib, so I tried using different versions of matplotlib, but the error persisted. I also considered that there might be a missing dependency or a conflict with another library, so I checked the ydata-profiling documentation for any specific version requirements or known issues, but didn't find anything relevant.
I was expecting the profile.to_file("report.html") line to generate a HTML report file summarizing the data in df_accidentes. However, instead, I encountered an AttributeError relating to matplotlib.cbook.
I searched StackOverflow for similar issues, particularly focusing on any AttributeError instances with ydata-profiling or matplotlib, but most of the questions were related to different errors or were using Conda instead of venv.
I haven't been able to find a solution that resolves this error yet, which is why I am seeking help here. I am wondering if there might be a known issue or a workaround to get the ydata-profiling library to generate the report as expected.
To fix the issue, I followed these steps:
Somehow that worked out just fine...