GAA-UAM / scikit-fda

Functional Data Analysis Python package
https://fda.readthedocs.io
BSD 3-Clause "New" or "Revised" License
287 stars 51 forks source link

I can not use the plots #540

Closed Roanol closed 1 year ago

Roanol commented 1 year ago

Describe the bug

when trying to plot it raises: TypeError("Instance and class checks can only be used with" TypeError: Instance and class checks can only be used with @runtime_checkable protocols

To Reproduce

any of the examples

from skfda import datasets from skfda.exploratory.depth import ModifiedBandDepth, IntegratedDepth from skfda.exploratory.visualization import Boxplot

import matplotlib.pyplot as plt import numpy as np

X, y = datasets.fetch_weather(return_X_y=True, as_frame=True) fd = X.iloc[:, 0].values fd_temperatures = fd.coordinates[0]

colormap = plt.cm.get_cmap('seismic') label_names = y.values.categories nlabels = len(label_names) label_colors = colormap(np.arange(nlabels) / (nlabels - 1))

fd_temperatures.plot(group=y.values.codes, group_colors=label_colors, group_names=label_names)

Expected behavior

Ploting something

Version information

  1. fdasrsf==2.4.1
  2. findiff==0.9.2
  3. fonttools==4.39.4
  4. matplotlib==3.7.1
  5. multimethod==1.9.1
  6. numpy==1.24.3
  7. pandas==2.0.2
  8. rdata==0.9
  9. scikit-datasets==0.2.2
  10. scikit-learn==1.2.2
  11. scipy==1.10.1
  12. setuptools = 67.8.0

Additional context Add any other context about the problem here.

vnmabus commented 1 year ago

Please, copy the stack trace of the exception here for diagnosing the problem.

Roanol commented 1 year ago

Traceback (most recent call last): File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "C:\Users\ANDRES OLIVERO\AppData\Local\Temp\ipykernel_25752\2989687894.py", line 1, in fd.scatter(s=0.5) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\skfda\representation\grid.py", line 897, in scatter return ScatterPlot(self, *args, kwargs).plot() File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\skfda\exploratory\visualization_baseplot.py", line 85, in plot fig, axes = self._set_figure_and_axes( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\skfda\exploratory\visualization_baseplot.py", line 130, in _set_figure_and_axes fig, axes = _set_figure_layout( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\skfda\exploratory\visualization_utils.py", line 216, in _set_figure_layout fig.add_subplot( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\figure.py", line 757, in add_subplot ax = projection_class(self, args, pkw) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axes_base.py", line 683, in init self.clear() File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axes_base.py", line 1395, in clear self.clear() File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axes_base.py", line 1312, in clear self.grid(False) # Disable grid on init to use rcParameter File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axes_base.py", line 3194, in grid self.xaxis.grid(visible, which=which, kwargs) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 1660, in grid self.set_tick_params(which='major', gridkw) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 947, in set_tick_params for tick in self.majorTicks: File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 594, in get tick = instance._get_tick(major=True) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 1551, in _get_tick return self._tick_class(self.axes, 0, major=major, tick_kw) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 417, in init super().init(args, kwargs) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 183, in init self._apply_tickdir(tickdir) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\axis.py", line 452, in _apply_tickdir self.tick1line.set_marker(mark1) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\lines.py", line 1193, in set_marker self._marker = MarkerStyle(marker, self._marker.get_fillstyle()) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\markers.py", line 272, in init self._set_marker(marker) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\matplotlib\markers.py", line 347, in _set_marker elif (isinstance(marker, Sized) and len(marker) in (2, 3) and File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\abc.py", line 98, in instancecheck return _abc_instancecheck(cls, instance) File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\abc.py", line 102, in subclasscheck return _abc_subclasscheck(cls, subclass) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\typing_extensions.py", line 583, in subclasscheck return super().subclasscheck(other) File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\abc.py", line 102, in subclasscheck return _abc_subclasscheck(cls, subclass) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\typing_extensions.py", line 639, in _proto_hook raise TypeError("Instance and class checks can only be used with" TypeError: Instance and class checks can only be used with @runtime_checkable protocols

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\interactiveshell.py", line 2105, in showtraceback stb = self.InteractiveTB.structured_traceback( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\ultratb.py", line 1396, in structured_traceback return FormattedTB.structured_traceback( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\ultratb.py", line 1287, in structured_traceback return VerboseTB.structured_traceback( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\ultratb.py", line 1140, in structured_traceback formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context, File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\ultratb.py", line 1055, in format_exception_as_a_whole frames.append(self.format_record(record)) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\ultratb.py", line 955, in format_record frame_info.lines, Colors, self.has_colors, lvals File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\IPython\core\ultratb.py", line 778, in lines return self._sd.lines File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\stack_data\utils.py", line 144, in cached_property_wrapper value = obj.dict[self.func.name] = self.func(obj) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\stack_data\core.py", line 734, in lines pieces = self.included_pieces File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\stack_data\utils.py", line 144, in cached_property_wrapper value = obj.dict[self.func.name] = self.func(obj) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\stack_data\core.py", line 681, in included_pieces pos = scope_pieces.index(self.executing_piece) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\stack_data\utils.py", line 144, in cached_property_wrapper value = obj.dict[self.func.name] = self.func(obj) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\stack_data\core.py", line 660, in executing_piece return only( File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\executing\executing.py", line 182, in only if isinstance(it, Sized): File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\typing.py", line 769, in instancecheck return self.subclasscheck(type(obj)) File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\typing.py", line 774, in subclasscheck return issubclass(cls, self.origin) File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\abc.py", line 102, in subclasscheck return _abc_subclasscheck(cls, subclass) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\typing_extensions.py", line 583, in subclasscheck return super().subclasscheck(other) File "C:\Users\ANDRES OLIVERO\AppData\Local\Programs\Python\Python38\lib\abc.py", line 102, in subclasscheck return _abc_subclasscheck(cls, subclass) File "c:\Users\ANDRES OLIVERO\Documents\Repos\Environments\functional_analysis\lib\site-packages\typing_extensions.py", line 639, in _proto_hook raise TypeError("Instance and class checks can only be used with" TypeError: Instance and class checks can only be used with @runtime_checkable protocols

Roanol commented 1 year ago

As you can see its in any kind of plot

vnmabus commented 1 year ago

What is the version of the typing_extensions package?

Roanol commented 1 year ago

typing_extensions==4.6.2

vnmabus commented 1 year ago

I was able to reproduce it and I am trying to solve this. As a stopgap measure you can downgrade that package to version 4.3, which worked well.

Roanol commented 1 year ago

thanks!

vnmabus commented 1 year ago

I traced this to a bug in the module typing_extensions (https://github.com/python/typing_extensions/issues/207), which in turn was caused by copying buggy behavior from Python 3.11 (https://github.com/python/cpython/issues/105144).

The authors of typing_extensions have updated their package to version 4.6.3, which should solve this issue. Please, tell me if that works for you.

gedeck commented 1 year ago

I came across the same issue and can confirm that upgrading typing-extensions to the latest version solves issue.

vnmabus commented 1 year ago

I will close the issue then, since it seems to be solved.