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

Persistence graphical tools improvements #504

Conversation

VincentRouvreau
Copy link
Contributor

@VincentRouvreau VincentRouvreau commented Jun 17, 2021

Fix #453
Fix #461
Review error management (no more prints, warnings and exceptions instead) and add unitary tests
No more plots in loop (optimization)

@VincentRouvreau VincentRouvreau marked this pull request as ready for review June 21, 2021 12:34
'''
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):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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)?

Copy link
Member

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)

Copy link
Contributor Author

@VincentRouvreau VincentRouvreau Aug 24, 2021

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

@mglisse
Copy link
Member

mglisse commented Aug 12, 2021

The comment "fix #453" is a bit short, and the changes are a bit hard to find with the reformatting.
What is the new behavior? By default it prints a warning once, the first time the plot function is called with a list that is too long?

@VincentRouvreau
Copy link
Contributor Author

VincentRouvreau commented Aug 24, 2021

The comment "fix #453" is a bit short, and the changes are a bit hard to find with the reformatting.
What is the new behavior? By default it prints a warning once, the first time the plot function is called with a list that is too long?

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 "always", but maybe we should define a class like a PlotWarning for instance to not impact other warnings.

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:
Copy link
Contributor

@Hind-M Hind-M Sep 8, 2021

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:

Suggested change
except ImportError:
except ImportError as error:

Copy link
Contributor Author

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warnings.warn("This function is not available, you may be missing matplotlib.")
print(error)

Copy link
Contributor Author

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.")
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.")
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.")
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@VincentRouvreau VincentRouvreau added the optimization It works, now make it faster label Apr 29, 2022
Copy link
Member

@mglisse mglisse left a 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.

Comment on lines +211 to +212
except ImportError as import_error:
warnings.warn(f"This function is not available.\nModuleNotFoundError: No module named '{import_error.name}'.")
Copy link
Member

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.

@VincentRouvreau VincentRouvreau merged commit 7491d4b into GUDHI:master May 9, 2022
@VincentRouvreau VincentRouvreau deleted the persistence_graphical_tools_improvements branch May 9, 2022 20:12
@VincentRouvreau VincentRouvreau added the 3.6.0 GUDHI version 3.6.0 label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.6.0 GUDHI version 3.6.0 optimization It works, now make it faster
Projects
None yet
3 participants