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

I can not use the plots #540

Closed
Roanol opened this issue May 31, 2023 · 10 comments
Closed

I can not use the plots #540

Roanol opened this issue May 31, 2023 · 10 comments
Labels

Comments

@Roanol
Copy link

Roanol commented May 31, 2023

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

  • OS: Windows 10
  • Python 3.8.10
  • scikit-fda version: both scikit-fda 0.8.1and develop branch
  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.

@Roanol Roanol added the bug label May 31, 2023
@vnmabus
Copy link
Member

vnmabus commented May 31, 2023

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

@Roanol
Copy link
Author

Roanol commented May 31, 2023

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
Copy link
Author

Roanol commented May 31, 2023

As you can see its in any kind of plot

@vnmabus
Copy link
Member

vnmabus commented May 31, 2023

What is the version of the typing_extensions package?

@Roanol
Copy link
Author

Roanol commented May 31, 2023

typing_extensions==4.6.2

@vnmabus
Copy link
Member

vnmabus commented May 31, 2023

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
Copy link
Author

Roanol commented May 31, 2023

thanks!

@vnmabus
Copy link
Member

vnmabus commented Jun 2, 2023

I traced this to a bug in the module typing_extensions (python/typing_extensions#207), which in turn was caused by copying buggy behavior from Python 3.11 (python/cpython#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
Copy link

gedeck commented Jun 14, 2023

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

@vnmabus
Copy link
Member

vnmabus commented Jun 14, 2023

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

@vnmabus vnmabus closed this as completed Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants