-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add keyword hide_f_block: bool = None
(La and Ac series) to ptable
plotters
#140
Conversation
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.
this looks great! 👍 all that's missing are some unit tests
@@ -793,6 +796,9 @@ def tick_fmt(val: float, _pos: int) -> str: | |||
) | (text_style or {}) | |||
|
|||
for symbol, row, column, *_ in df_ptable.itertuples(): | |||
if hide_f_block and (row in (6, 7)): |
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 thought I would do this after refactor all other plotters with the new PTableProjector
, but thanks for fixing this.
…into ptable_hide_la-ac
Thanks for reviewing.
Exactly, but I found it tricky to write unit tests for plotters. Do you have any suggestions? Assert a |
i would test that |
Sounds great. I would add this later :) |
great. i think once this is merged, we're ready for a v0.8.2 release so people who install from pypi can start using |
…_ptable_heatmap_splits
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 think we can be a bit smarter about the hide_f_block
default behavior. let's set it to None
by default and then use True
or False
depending on whether we have non-zero values for any rare earths. passing True
or False
explicitly of course will override this behavior
assets/ptable-heatmap-splits.svg
Outdated
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.
nice, much better now. didn't actually notice all the white space before
Excellent idea. Let's do it. |
pymatviz/ptable.py
Outdated
for atom_num in [*range(57, 72), *range(89, 104)] # rare earths | ||
# check if data is present for f-block elements | ||
if (elem := Element.from_Z(atom_num).symbol) in self.data.index # type: ignore[union-attr] | ||
and self.data.loc[elem, "Value"] # type: ignore[union-attr] |
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.
one more thing to change here: it's always a good to maintain SSOT to avoid drift and to ensure it remains easy to rename things in the future. the "Value"
key is hard-coded in many places in this file. would be better to add a new key in init.py
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.
Yes, as we're hard coding the column names:
Lines 217 to 254 in 39fd71e
def data_preprocessor(data: SupportedDataType) -> pd.DataFrame: | |
"""Preprocess input data for ptable plotters, including: | |
- Convert all data types to pd.DataFrame. | |
- Impute missing values. | |
- Handle anomalies such as NaN, infinity. | |
- Write vmin/vmax as metadata into the DataFrame. | |
Returns: | |
pd.DataFrame: The preprocessed DataFrame with element names | |
as index and values as columns. | |
Example: | |
>>> data_dict: dict = { | |
"H": 1.0, | |
"He": [2.0, 4.0], | |
"Li": [[6.0, 8.0], [10.0, 12.0]], | |
} | |
OR | |
>>> data_df: pd.DataFrame = pd.DataFrame( | |
data_dict.items(), | |
columns=["Element", "Value"] | |
).set_index("Element") | |
OR | |
>>> data_series: pd.Series = pd.Series(data_dict) | |
>>> preprocess_data(data_dict/df/series) | |
Element Value | |
0 H [1.0, ] | |
1 He [2.0, 4.0] | |
2 Li [[6.0, 8.0], [10.0, 12.0]] | |
Metadata: | |
vmin: 1.0 | |
vmax: 12.0 | |
""" |
hide_f_block: bool = None
(La and Ac series) to ptable
plotters
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.
thanks so much for this @DanielYang59! 👍
@@ -235,8 +239,8 @@ def data_preprocessor(data: SupportedDataType) -> pd.DataFrame: | |||
OR | |||
>>> data_df: pd.DataFrame = pd.DataFrame( | |||
data_dict.items(), | |||
columns=["Element", "Value"] | |||
).set_index("Element") | |||
columns=[{element_col}, {value_col}] |
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.
It looks like this breaks the site builder workflow. I should have used a raw string instead. Please help me fix this. Thanks!
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.
will fix, PR incoming for SSOT of keys across the whole code base
Great to collaborate with you on this one. Thanks! |
Summary
Allow easy hiding of f-block (La and Ac series) in ptable plotter, to close Several possible improvements for
ptable_heatmap
plotter #138(Need discussion) Set some arguments to be keyword-only
Rationale: most args in ptable plotters are complicated, and set them as keyword-only might reduce ambiguity.
TODO