-
Notifications
You must be signed in to change notification settings - Fork 79
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
Fix test issues #660
base: master
Are you sure you want to change the base?
Fix test issues #660
Conversation
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Warning Rate limit exceeded@zz11ss11zz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 55 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe pull request introduces several modifications across multiple files. Key changes include updates to the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (3)
src/maml/data/_mp.py (2)
Line range hint
24-32
: Add Google format docstrings to theget
method.As per the PR objectives, Google format docstrings should be added. Please update the method's docstring to include more detailed information about the parameters and return value. Here's a suggested format:
def get(self, criteria: str | dict, properties: list[str]) -> pd.DataFrame: """ Retrieve data from the Materials Project based on given criteria and properties. Args: criteria (Union[str, dict]): The search criteria for querying materials. Can be a string (e.g., material formula) or a dictionary of properties. properties (List[str]): A list of properties to retrieve for each material. Returns: pd.DataFrame: A pandas DataFrame containing the requested properties for materials matching the given criteria. Raises: TypeError: If the input types are incorrect. ConnectionError: If there's an issue connecting to the Materials Project API. """ # Method implementation...Also, consider adding a
Examples
section to the docstring to demonstrate how to use this method.
Line range hint
1-32
: Summary of review and next steps
The addition of
# type: ignore
comments contradicts the PR objective of usingmypy
for type checking. Consider addressing the underlying type issues instead of suppressing them.The method lacks Google format docstrings as required by the PR objectives. Add detailed docstrings to improve code documentation.
The overall structure and functionality of the
MaterialsProject
class appear correct, but there's room for improvement in terms of type annotations and documentation.Next steps:
- Run
mypy
on this file to identify specific type issues and address them properly.- Add Google format docstrings to all methods in this class.
- Consider adding examples in the docstrings to demonstrate usage.
- If you haven't already, apply these improvements to other files changed in this PR as well.
src/maml/apps/gbe/describer.py (1)
Line range hint
1-477
: Address PR objectives: Add Google format docstrings and type annotationsThe current changes do not fully address the PR objectives. Please consider the following points:
Google format docstrings: Add Google format docstrings to all functions and classes in this file. This will improve code documentation and readability.
Type annotations: Instead of using
# type: ignore
comments, add proper type annotations throughout the file. This includes function parameters, return types, and variable annotations where necessary.Use
ruff
andmypy
: Ensure that you've runruff
for linting andmypy
for type checking on this file. Address any issues they raise, rather than suppressing them with# type: ignore
.Here's an example of how you might improve a function with Google format docstrings and type annotations:
from typing import List, Dict, Any def get_structural_feature(db_entry: Dict[str, Any], features: List[Any] | None = None) -> pd.DataFrame: """ Get the structural features from a database entry. Args: db_entry: A dictionary containing the database entry information. features: A list of features to extract. If None, default features will be used. Returns: A pandas DataFrame containing the extracted structural features. Raises: ValueError: If an invalid feature is requested. """ # Function implementation...Please apply similar improvements throughout the file to meet the PR objectives.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
- pyproject.toml (1 hunks)
- requirements.txt (1 hunks)
- src/maml/apps/bowsr/model/dft.py (1 hunks)
- src/maml/apps/gbe/describer.py (2 hunks)
- src/maml/apps/gbe/utils.py (1 hunks)
- src/maml/data/_mp.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/maml/apps/bowsr/model/dft.py
🔇 Additional comments (6)
requirements.txt (1)
7-7
: Verify the necessity and compatibility of the new dependency.The addition of
mp-api==0.42.2
to the requirements file introduces a new dependency to the project. While this package might be necessary for addressing test issues or implementing new features, there are a few points to consider:
Relevance: Ensure that this package is directly related to fixing the test issues mentioned in the PR objectives or is essential for the project's functionality.
Version compatibility: Verify that version 0.42.2 is compatible with the other packages in the project, especially
pymatgen==2024.9.17.1
, as both seem to be related to materials science.Minimal version specification: Consider if it's necessary to pin the exact version (==0.42.2) or if a more flexible version specification (e.g., >=0.42.2,<0.43) would be more appropriate to allow for minor updates and bug fixes.
Documentation: Ensure that the reason for adding this dependency is documented, either in the code comments, PR description, or project documentation.
To help verify the necessity and impact of this new dependency, you can run the following commands:
These commands will help identify where
mp-api
is used in the project, check for any potential version conflicts, and list any packages that depend onmp-api
.src/maml/data/_mp.py (1)
30-30
:⚠️ Potential issueReconsider the use of
# type: ignore
comments.The addition of
# type: ignore
comments, both on the method signature and thesearch
method call, goes against the PR objective of checking type annotations withmypy
. While these comments suppress type-checking warnings, they may hide potential issues in the code.Instead of ignoring type checks, consider the following alternatives:
- Add proper type annotations to resolve the type-checking errors.
- If the
MPRester.materials.search
method is incorrectly typed in the library, consider creating a stub file or submitting a PR to thepymatgen
library to fix the type annotations.- If the type ignore is absolutely necessary, add a comment explaining why it's needed and consider using a more specific ignore comment (e.g.,
# type: ignore[attr-defined]
) to target the specific issue.To help identify the specific type issues, please run the following command and provide the output:
src/maml/apps/gbe/utils.py (2)
78-78
: Investigate the need for type ignore commentThe addition of
# type: ignore
to therester.get_structure_by_material_id()
call suggests a type-related issue. While this comment bypasses the type checker, it's important to understand and address the underlying cause.Could you provide more information about why this type ignore was necessary? Consider the following steps:
- Investigate the exact type error that was being raised.
- Check if the
pymatgen
library has proper type annotations for this method.- If possible, add appropriate type annotations to resolve the issue without using
# type: ignore
.This approach will help maintain type safety and improve code quality in the long run.
To help investigate this issue, you can run the following command to check for type errors in this file:
This will help identify any other type-related issues in the file and provide more context for the necessary fix.
Line range hint
1-89
: Address PR objectives and improve overall code qualityTo align with the PR objectives and enhance code quality, consider the following improvements:
Add Google format docstrings:
The PR objectives mention adding Google format docstrings. Please update all function docstrings to follow this format. For example, theload_data
function could be updated as follows:def load_data(filename: str | None = None) -> list: """ Helper function to load the data. Args: filename (str | None): The filename of the data. If None, loads the default 361 data. Returns: list: The loaded data. Raises: FileNotFoundError: If the specified file doesn't exist. """Complete type annotations:
While some functions have type annotations, others are missing them. Please add type annotations to all functions and variables. For example:def load_b0_dict() -> dict[str, float]: """ Helper function to retrieve the b0 data. Returns: dict[str, float]: A dictionary mapping elements to their b0 values. Raises: MPRestError: If no MAPI_KEY is found in the environment. """Improve error handling:
Consider adding more specific error handling. For example, in theload_b0_dict
function:if not os.getenv("MAPI_KEY"): raise ValueError("No MAPI_KEY found in environment variables")Code organization:
Consider grouping related functions together and adding comments to separate different sections of the file.Add
duecredit
decorators:
If any of these functions are based on academic papers, addduecredit
decorators as mentioned in the PR objectives.To verify the current state of docstrings and type annotations, you can run:
These commands will help identify areas that need improvement to meet the PR objectives.
pyproject.toml (2)
115-122
: Changes align with PR objectives but require careful consideration.The additions to the
lint.ignore
list are consistent with the PR objectives, particularly the mention of adding Google format docstrings and usingruff
for verification. However, it's crucial to ensure that these changes don't compromise code quality in the long term.Consider the following recommendations:
- Document the rationale for ignoring each rule in a comment within the
pyproject.toml
file.- Set up a plan to gradually address and remove these ignore rules in future iterations, if possible.
- Ensure that the team is aware of these changes and understands the implications for code reviews and maintenance.
Also applies to: 129-129
115-122
: Consider the implications of ignoring additional linting rules.The following linting rules have been added to the ignore list:
- D103: Missing docstring in public function
- D200: One-line docstring should fit on one line with quotes
- D415: First line should end with a period, question mark, or exclamation point
- E501: Line too long
- E741: Do not use variables named 'l', 'O', or 'I'
- RET504: Unnecessary assignment before
return
statementWhile ignoring these rules may simplify development in the short term, it could lead to reduced code documentation quality, potential readability issues, and slightly less efficient code.
To ensure this change aligns with the project's goals, please run the following script to check the prevalence of these issues in the codebase:
This script will help quantify the impact of ignoring these rules and inform whether this change is justified.
Also applies to: 129-129
@@ -206,7 +206,7 @@ def get_structural_feature(db_entry: dict, features: list | None = None) -> pd.D | |||
if gb_plane.shape[0] == 4: | |||
gb_plane = convert_hcp_plane(list(gb_plane)) | |||
rotation_axis = convert_hcp_direction(rotation_axis, lat_type=sg.get_crystal_system()) | |||
d_gb = bulk_conv.lattice.d_hkl(gb_plane) | |||
d_gb = bulk_conv.lattice.d_hkl(gb_plane) # type: ignore |
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.
Investigate and fix the type issue instead of using # type: ignore
The addition of # type: ignore
suggests there's a type-related issue with bulk_conv.lattice.d_hkl(gb_plane)
. Instead of suppressing the type checker, it would be better to investigate and fix the underlying issue. This aligns with the PR objective of adding proper type annotations.
Consider the following steps:
- Check the return type of
bulk_conv.lattice.d_hkl()
. - Ensure that
gb_plane
is of the correct type expected by the method. - Add appropriate type annotations to resolve the issue.
If you need assistance in resolving this, please provide more context about the d_hkl
method and the expected types.
@@ -266,15 +266,15 @@ | |||
rester = MPRester(mp_api) | |||
else: | |||
raise MPRestError("Please provide API key to access Materials Project") | |||
bulk = rester.materials.search(material_ids=[db_entry["material_id"]])[0] | |||
bulk = rester.materials.search(material_ids=[db_entry["material_id"]])[0] # type: ignore |
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.
Add explicit type annotation instead of using # type: ignore
Rather than suppressing the type checker with # type: ignore
, it would be more appropriate to add an explicit type annotation for the bulk
variable. This approach aligns with the PR objective of adding proper type annotations.
Consider the following steps:
- Determine the expected return type of
rester.materials.search()
. - Add an explicit type annotation for the
bulk
variable.
For example, if the expected type is Material
, you could write:
bulk: Material = rester.materials.search(material_ids=[db_entry["material_id"]])[0]
If you're unsure about the correct type, please consult the documentation for the MPRester
class or the return type of the materials.search()
method.
bulk_s = rester.get_structure_by_material_id(db_entry["material_id"]) # type: ignore | ||
if bulk: | ||
f_dict[preset.bdensity.str_name] = bulk[0]["density"] | ||
f_dict[preset.G.str_name] = bulk[0]["elasticity"]["G_VRH"] | ||
el = Element(db_entry["pretty_formula"]) | ||
f_dict[preset.ar.str_name] = el.atomic_radius | ||
f_dict[preset.a0.str_name] = bulk_s.lattice.a | ||
f_dict[preset.e_coh.str_name] = rester.get_cohesive_energy(db_entry["material_id"]) | ||
f_dict[preset.e_coh.str_name] = rester.get_cohesive_energy(db_entry["material_id"]) # type: ignore |
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.
Add explicit type annotation instead of using # type: ignore
Instead of using # type: ignore
to suppress the type checker, it would be better to add an explicit type annotation for the return value of rester.get_cohesive_energy()
. This approach is in line with the PR objective of adding proper type annotations.
Consider the following steps:
- Determine the expected return type of
rester.get_cohesive_energy()
. - Add an explicit type annotation for the return value.
For example, if the expected type is float
, you could write:
cohesive_energy: float = rester.get_cohesive_energy(db_entry["material_id"])
f_dict[preset.e_coh.str_name] = cohesive_energy
If you're unsure about the correct return type, please consult the documentation for the MPRester
class or the get_cohesive_energy()
method.
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Summary
Major changes:
Todos
If this is work in progress, what else needs to be done?
Checklist
ruff
.mypy
.duecredit
@due.dcite
decorators to reference relevant papers by DOI (example)Tip: Install
pre-commit
hooks to auto-check types and linting before every commit: