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

Show FutureWarning and DeprecationWarning for pytest #4138

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Oct 26, 2024

Summary

@DanielYang59 DanielYang59 force-pushed the show-deprecation-warn branch 3 times, most recently from 26ed4ec to 963dff5 Compare October 27, 2024 06:30
pyproject.toml Outdated Show resolved Hide resolved
@@ -274,7 +274,10 @@ def _get_symmetry(self) -> tuple[NDArray, NDArray]:
"translations" gives the numpy float64 array of the translation
vectors in scaled positions.
"""
dct = spglib.get_symmetry(self._cell, symprec=self._symprec, angle_tolerance=self._angle_tol)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this we get:

tests/analysis/chemenv/connectivity/test_structure_connectivity.py::TestStructureConnectivity::test_serialization
  /Users/yang/developer/pymatgen/venv312/lib/python3.12/site-packages/spglib/spglib.py:640: DeprecationWarning: Use get_magnetic_symmetry() for cell with magnetic moments.
    warnings.warn(

But this doesn't look like a in place replace, for:

dct = spglib.get_magnetic_symmetry(self._cell, symprec=self._symprec, angle_tolerance=self._angle_tol)

I got 6 test failure:


tests/symmetry/test_analyzer.py ..F....FF.F..........F.F..........                                                                             [100%]

====================================================================== FAILURES ======================================================================
__________________________________________ TestSpacegroupAnalyzer.test_get_conventional_standard_structure ___________________________________________

# TODO: scipy.misc.central_diff_weights is deprecated in SciPy v1.10.0;
# and will be completely removed in SciPy v1.12.0.
# You may consider using findiff: https://github.com/maroba/findiff
# or numdifftools: https://github.com/pbrod/numdifftools
assert_allclose(central_29, central_diff_weights(9, 2))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

central_diff_weights should have been removed (but for some reason not yet), and the replacement is another package, comment this out for now?

dEdV = derivative(func, volume, dx=1e-3)
d2EdV2 = derivative(func, volume, dx=1e-3, n=2, order=5)
d3EdV3 = derivative(func, volume, dx=1e-3, n=3, order=7)
with warnings.catch_warnings():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another deprecation requesting findiff or numdifftools from scipy as 6a62d63

@@ -913,14 +913,18 @@ def write_inputs(self, output_dir: str, **kwargs) -> None:
output_dir (str): Directory to output the input files.
**kwargs: kwargs supported by LammpsData.write_file.
"""
write_lammps_inputs(
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 27, 2024

Choose a reason for hiding this comment

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

Need some LAMMPS expert to fix this, this class has only one method but deprecated (the class itself is not):

class LammpsTemplateGen(TemplateInputGen):
"""Create an InputSet object for a LAMMPS run based on a template file.
The input script is constructed by substituting variables into placeholders
in the template file using python's Template.safe_substitute() function.
The data file containing coordinates and topology information can be provided
as a LammpsData instance. Alternatively, you can include a read_data command
in the template file that points to an existing data file.
Other supporting files are not handled at the moment.
To write the input files to a directory, call LammpsTemplateSet.write_input()
See pymatgen.io.template.py for additional documentation of this method.
"""
def get_input_set(

@@ -649,8 +649,8 @@ def test_attributes(self):
atomlist = ["O1", "Mn2"]
types = ["O", "Mn"]
num_atoms = 2
assert charge_Mulliken == self.charge2.Mulliken
assert charge_Loewdin == self.charge2.Loewdin
assert charge_Mulliken == self.charge2.mulliken
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 27, 2024

Choose a reason for hiding this comment

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

@JaGeo @QuantumChemist Can you please help me have a look at this LOBTSER change 8c1cee5? A lot of test code access deprecated attribute, I wish it's not intended (to test deprecated API, expect for that one I filtered)

tests/io/lobster/test_lobsterenv.py: 206 warnings
  /home/runner/work/pymatgen/pymatgen/src/pymatgen/io/lobster/lobsterenv.py:193: DeprecationWarning: Mulliken is deprecated
  Use `mulliken` instead.
    self.valences = chg.Mulliken

tests/io/lobster/test_lobsterenv.py: 17 warnings
  /home/runner/work/pymatgen/pymatgen/src/pymatgen/io/lobster/lobsterenv.py:195: DeprecationWarning: Loewdin is deprecated
  Use `loewdin` instead.
    self.valences = chg.Loewdin

tests/io/lobster/test_lobsterenv.py::TestLobsterNeighbors::test_get_anion_types
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_lobsterenv.py:341: FutureWarning: get_anion_types is deprecated; use anion_types in pymatgen.io.lobster.lobsterenv instead.
    assert self.chem_env_lobster0_second.get_anion_types() == {Element("O")}

tests/io/lobster/test_outputs.py::TestCharge::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:652: DeprecationWarning: Mulliken is deprecated
  Use `mulliken` instead.
    assert charge_Mulliken == self.charge2.Mulliken

tests/io/lobster/test_outputs.py::TestCharge::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:653: DeprecationWarning: Loewdin is deprecated
  Use `loewdin` instead.
    assert charge_Loewdin == self.charge2.Loewdin

tests/io/lobster/test_outputs.py: 4128 warnings
  /home/runner/work/pymatgen/pymatgen/src/pymatgen/io/lobster/outputs.py:1680: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    self.band_overlaps_dict[spin]["matrices"].append(np.matrix(overlaps))

tests/io/lobster/test_outputs.py::TestBandoverlaps::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:1494: DeprecationWarning: bandoverlapsdict is deprecated
  Use `band_overlaps_dict` instead.
    bo_dict = self.band_overlaps1.bandoverlapsdict

tests/io/lobster/test_outputs.py::TestBandoverlaps::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:1496: DeprecationWarning: bandoverlapsdict is deprecated
  Use `band_overlaps_dict` instead.
    assert self.band_overlaps1_new.bandoverlapsdict[Spin.up]["max_deviations"][10] == approx(0.0640933)

tests/io/lobster/test_outputs.py::TestBandoverlaps::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:1498: DeprecationWarning: bandoverlapsdict is deprecated
  Use `band_overlaps_dict` instead.
    assert self.band_overlaps1_new.bandoverlapsdict[Spin.up]["matrices"][10].item(-1, -1) == approx(1.0)

tests/io/lobster/test_outputs.py::TestBandoverlaps::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:1500: DeprecationWarning: bandoverlapsdict is deprecated
  Use `band_overlaps_dict` instead.
    assert self.band_overlaps1_new.bandoverlapsdict[Spin.up]["matrices"][10].item(0, 0) == approx(0.995849)

tests/io/lobster/test_outputs.py::TestBandoverlaps::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:1503: DeprecationWarning: bandoverlapsdict is deprecated
  Use `band_overlaps_dict` instead.
    assert self.band_overlaps1_new.bandoverlapsdict[Spin.down]["max_deviations"][9] == approx(0.064369)

tests/io/lobster/test_outputs.py::TestBandoverlaps::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:1505: DeprecationWarning: bandoverlapsdict is deprecated
  Use `band_overlaps_dict` instead.
    assert self.band_overlaps1_new.bandoverlapsdict[Spin.down]["matrices"][9].item(0, -1) == approx(1.37447e-09)

tests/io/lobster/test_outputs.py::TestSitePotentials::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:2211: DeprecationWarning: sitepotentials_Loewdin is deprecated
  Use `sitepotentials_loewdin` instead.
    ]

tests/io/lobster/test_outputs.py::TestSitePotentials::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:2218: DeprecationWarning: sitepotentials_Mulliken is deprecated
  Use `sitepotentials_mulliken` instead.
    ]

tests/io/lobster/test_outputs.py::TestSitePotentials::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:2219: DeprecationWarning: madelungenergies_Loewdin is deprecated
  Use `madelungenergies_loewdin` instead.
    assert self.sitepotential.madelungenergies_Loewdin == approx(-28.64)

tests/io/lobster/test_outputs.py::TestSitePotentials::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:2220: DeprecationWarning: madelungenergies_Mulliken is deprecated
  Use `madelungenergies_mulliken` instead.
    assert self.sitepotential.madelungenergies_Mulliken == approx(-40.02)

tests/io/lobster/test_outputs.py::TestMadelungEnergies::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:2256: DeprecationWarning: madelungenergies_Loewdin is deprecated
  Use `madelungenergies_loewdin` instead.
    assert self.madelungenergies.madelungenergies_Loewdin == approx(-28.64)

tests/io/lobster/test_outputs.py::TestMadelungEnergies::test_attributes
  /home/runner/work/pymatgen/pymatgen/tests/io/lobster/test_outputs.py:2257: DeprecationWarning: madelungenergies_Mulliken is deprecated
  Use `madelungenergies_mulliken` instead.
    assert self.madelungenergies.madelungenergies_Mulliken == approx(-40.02)

@@ -320,6 +320,8 @@ def _get_exchange_df(self):

# Ignore the row if it is a duplicate to avoid singular matrix
# Create a temporary DataFrame with the new row
ex_mat = ex_mat.dropna(how="all", axis=1)
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 27, 2024

Choose a reason for hiding this comment

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

I'm not 100% sure about this change (regarding the axis), but it should be the columns from the warning message:

  /Users/yang/developer/pymatgen/src/pymatgen/analysis/magnetism/heisenberg.py:325: 
FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. 
In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. 
To retain the old behavior, exclude the relevant entries before the concat operation.
    temp_df = pd.concat([ex_mat, ex_row], ignore_index=True)

@@ -578,7 +578,7 @@ def get_plotly(
x=[0],
y=[0],
z=[0],
colorbar=go.ColorBar(
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 27, 2024

Choose a reason for hiding this comment

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

I'm not experienced with plotly, could any one help me confirm this?

plotly.graph_objs.ColorBar is deprecated.
  Please replace it with one of the following more specific types
    - plotly.graph_objs.scatter.marker.ColorBar
    - plotly.graph_objs.surface.ColorBar
    - etc.

Looks like the correct colorbar for mesh3d:

# Add colorbar
color_scale = sorted(color_scale, key=lambda c: c[0])
colorbar = go.Mesh3d(
x=[0],
y=[0],
z=[0],
colorbar=go.ColorBar(
title={
"text": f"Surface energy {units}",
"side": "right",
"font": {"size": 25},
},
ticktext=ticktext,
tickvals=tickvals,
),

@@ -1677,7 +1677,7 @@ def _read(self, lines: list[str], spin_numbers: list[int]) -> None:
_lines.append(float(el))
overlaps.append(_lines)
if len(overlaps) == len(_lines):
self.band_overlaps_dict[spin]["matrices"].append(np.matrix(overlaps))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JaGeo would appreciate it if you could have a look at this as well, got:

  /Users/yang/developer/pymatgen/src/pymatgen/io/lobster/outputs.py:1680: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    self.band_overlaps_dict[spin]["matrices"].append(np.matrix(overlaps))

And as per the manual:

‘array’ or ‘matrix’? Which should I use?

Historically, NumPy has provided a special matrix type, np.matrix, which is a subclass of ndarray which makes binary operations linear algebra operations. You may see it used in some existing code instead of np.array. So, which one to use?

Short answer
Use arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vampire_interface (pymatgen/analysis/magnetism/heisenberg.py:323:)
1 participant