-
Notifications
You must be signed in to change notification settings - Fork 67
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
Persistence graphical tools improvements #504
Persistence graphical tools improvements #504
Conversation
…ots in plot_persistence_diagram. Fix GUDHI#453 and factorize code
…e same dimensions as C as it is deprecated since 3.3
…d exceptions instead)
''' | ||
if isinstance(a[0][1], np.float64) or isinstance(a[0][1], float): | ||
""" | ||
if isinstance(a[0][1], np.floating) or isinstance(a[0][1], float): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check both np.floating and float ? I'm wondering if np.floating already includes float since it handles all floating-point scalar types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.floating
includes np.float64
and np.float32
.
I don't know if it can happen, but I find nice we can plot float64 and float32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, the type to check is different even if it could be the same precision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.issubdtype(type(a[0][1]), np.floating)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(for the syntax, isinstance(x,t1) or isinstance(x,t2)
can be written isinstance(x,(t1,t2))
I believe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks, I didn't know this nicer syntax. Done on 87da488
The comment "fix #453" is a bit short, and the changes are a bit hard to find with the reformatting. |
I let the warning filter to default (which means "print the first occurrence of matching warnings for each location (module + line number) where the warning is issued"). I could set it to Or maybe I should just document the behaviour. |
@lru_cache(maxsize=1) | ||
def _matplotlib_can_use_tex(): | ||
"""This function returns True if matplotlib can deal with LaTeX, False otherwise. | ||
The returned value is cached. | ||
""" | ||
try: | ||
from matplotlib import checkdep_usetex | ||
|
||
return checkdep_usetex(True) | ||
except ImportError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more explicit if we print the import error instead?
For example:
except ImportError: | |
except ImportError as error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done on 55b15a7
return checkdep_usetex(True) | ||
except ImportError: | ||
print("This function is not available, you may be missing matplotlib.") | ||
warnings.warn("This function is not available, you may be missing matplotlib.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warnings.warn("This function is not available, you may be missing matplotlib.") | |
print(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the use of warning and modify the message on 55b15a7
error
is not directly printable, dev only have access to its name
and path
(cf. ImportError)
return axes | ||
|
||
except ImportError: | ||
print("This function is not available, you may be missing matplotlib.") | ||
warnings.warn("This function is not available, you may be missing matplotlib.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the import error print ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
return axes | ||
|
||
except ImportError: | ||
print("This function is not available, you may be missing matplotlib.") | ||
warnings.warn("This function is not available, you may be missing matplotlib.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the import error print ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
print( | ||
"This function is not available, you may be missing matplotlib and/or scipy." | ||
) | ||
warnings.warn("This function is not available, you may be missing matplotlib and/or scipy.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the import error print ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't really check the details, but if you think it is good, go ahead and merge it.
except ImportError as import_error: | ||
warnings.warn(f"This function is not available.\nModuleNotFoundError: No module named '{import_error.name}'.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see how that's better than not catching the exception, but it was already like that before the PR, so ok.
Fix #453
Fix #461
Review error management (no more prints, warnings and exceptions instead) and add unitary tests
No more plots in loop (optimization)