Compatibility interface - handle different types of potentials#277
Compatibility interface - handle different types of potentials#277jan-janssen merged 7 commits intomainfrom
Conversation
for more information, see https://pre-commit.ci
WalkthroughThe compatibility Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #277 +/- ##
==========================================
+ Coverage 92.51% 92.56% +0.05%
==========================================
Files 8 8
Lines 948 955 +7
==========================================
+ Hits 877 884 +7
Misses 71 71 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_compatibility_file.py (1)
87-90: Tests now cover Series input; consider adding coverage for DataFrame and invalid typesPassing the result of
get_potential_by_nameexercises the newpandas.Seriesbranch inlammps_file_interface_function. To fully lock in the new behavior, you might also:
- Add a test that passes a one-row
pandas.DataFrameand asserts identical behavior.- Add a small negative test that passes an unsupported type and asserts a
TypeError.This would make the expanded input handling harder to regress.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pyiron_lammps/compatibility/file.py(2 hunks)tests/test_compatibility_file.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/test_compatibility_file.py (2)
pyiron_lammps/structure.py (2)
potential(220-221)potential(224-225)pyiron_lammps/potential.py (1)
get_potential_by_name(349-355)
pyiron_lammps/compatibility/file.py (2)
pyiron_lammps/structure.py (2)
potential(220-221)potential(224-225)pyiron_lammps/potential.py (1)
get_potential_by_name(349-355)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: unittest_matrix (windows-latest, 3.14)
🔇 Additional comments (1)
tests/test_compatibility_file.py (1)
6-6: Newget_potential_by_nameimport is appropriateImporting
get_potential_by_namehere is consistent with the new interface that accepts resolved potential objects, and it keeps the test self-contained around how the potential is obtained.
| import subprocess | ||
| from typing import Optional | ||
|
|
||
| import pandas |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, get the file and check its size
wc -l pyiron_lammps/compatibility/file.pyRepository: pyiron/pyiron_lammps
Length of output: 103
🏁 Script executed:
#!/bin/bash
# Read the file to see the full context around the import and the function
cat -n pyiron_lammps/compatibility/file.pyRepository: pyiron/pyiron_lammps
Length of output: 10597
🌐 Web query:
pandas DataFrame.iloc[0] Series dict-like access API stable 2.3 2024
💡 Result:
Short answer: Yes — df.iloc[0] returns a pandas.Series and you can use label/dict-like access on that Series (e.g. s['col'], s.get('col'), s.keys(), s.items(), s.to_dict()). This is the documented and stable API in pandas 2.3. At the same time note that pandas has deprecated treating integer keys on a Series as positional (use ser.iloc[...] for positional access); that deprecation does not remove label/dict-like access. [1][2][3]
Sources:
- pandas.DataFrame.iloc documentation (shows iloc returns a Series when selecting a single row). [1]
- pandas.Series indexing/API (shows Series methods and label access like getitem, get, keys, items, to_dict). [2]
- Discussion / warning about Series.getitem treating integer keys as positions being deprecated (use .iloc for positions). [3]
Update type annotation, docstring, and error message for the potential parameter
The implementation at lines 91–100 correctly supports str, pandas.DataFrame, and pandas.Series inputs, using stable pandas APIs (DataFrame.iloc[0] returning a Series, and dict-like access on Series via ["key"]). However, three documentation gaps remain:
- Type annotation (line 22): Currently declares
potential: str, should beUnion[str, pandas.DataFrame, pandas.Series]to match the actual behavior. - Docstring (line 54): Currently describes only the string case ("Name of the LAMMPS potential…"), should document all three accepted types.
- Error handling (line 100): The fallback raises a bare
TypeError()with no message; adding context (e.g., "Unsupported type for potential; expected str, DataFrame, or Series") will improve debuggability.
These are non-breaking refinements that align the public API documentation with the actual implementation.
🤖 Prompt for AI Agents
In pyiron_lammps/compatibility/file.py around lines 22, 54, and 100, update the
API docs and error handling to match the implementation: change the function
parameter type annotation from potential: str to potential: Union[str,
pandas.DataFrame, pandas.Series] (add "from typing import Union" at top or use
typing.Union), expand the docstring at line 54 to document all three accepted
types and their meanings/handling (string = potential name, DataFrame = table
where first row is used, Series = dict-like mapping for keys), and replace the
bare TypeError() at line 100 with a descriptive message such as
TypeError("Unsupported type for potential; expected str, pandas.DataFrame, or
pandas.Series") to aid debugging.
# Conflicts: # tests/test_compatibility_file.py
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/test_compatibility_file.py (1)
145-160: DataFrame-basedpotentialpath is well covered; consider minor cleanupsThe pattern
potential = get_potential_by_name(...) potential=pandas.DataFrame({k: [potential[k]] for k in potential.keys()})correctly constructs a 1-row
DataFrameand exercises thepandas.DataFramebranch oflammps_file_interface_function. Functionally this is solid.Two small polish suggestions:
- You can simplify the DataFrame construction if you like, e.g.:
potential = get_potential_by_name(...) potential = pandas.DataFrame([potential])which produces an equivalent 1-row DataFrame with the same columns.
- Ruff flags
shell_outputhere as unused. To satisfy linting and make the intent explicit, you can rename it to a throwaway variable:- shell_output, parsed_output, job_crashed = lammps_file_interface_function( + _shell_output, parsed_output, job_crashed = lammps_file_interface_function(Both changes are optional but would keep the tests a bit cleaner and lint-free.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/test_compatibility_file.py(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_compatibility_file.py (2)
pyiron_lammps/compatibility/file.py (1)
lammps_file_interface_function(19-188)pyiron_lammps/potential.py (1)
get_potential_by_name(349-355)
🪛 Ruff (0.14.6)
tests/test_compatibility_file.py
149-149: Unpacked variable shell_output is never used
Prefix it with an underscore or any other dummy variable pattern
(RUF059)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: unittest_matrix (macos-latest, 3.14)
- GitHub Check: unittest_matrix (windows-latest, 3.14)
🔇 Additional comments (3)
tests/test_compatibility_file.py (3)
5-7: Imports align with new potential-handling pathsAdding
pandasandget_potential_by_namematches the newlammps_file_interface_functioninterface accepting Series/DataFrame. No issues here.
40-48: Good negative test for invalidpotentialtypeAsserting a
TypeErrorforpotential=1correctly verifies the new contract that onlystr,pandas.Series, orpandas.DataFrameare accepted. This nicely pins down the error behavior for unsupported types.
94-109: Series-basedpotentialuse correctly exercises the new code pathPassing
potential=get_potential_by_name(...)makestest_calc_md_nptexplicitly hit thepandas.Seriesbranch inlammps_file_interface_function, while still using the same resource path as the function. This is a clean way to test the new interface without changing the physical potential files.
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.