Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions news/remove-setscattering.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Removed:**

* Remove the deprecated ``setScatteringFactorTableByType`` method from
``ScatteringFactorTableOwner``, ``PDFCalculator``, and ``DebyePDFCalculator``.
39 changes: 3 additions & 36 deletions src/extensions/wrap_PDFCalculators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,9 @@ Use PeakWidthModel.getRegisteredTypes() for a set of registered names.\n\

const char* doc_ScatteringFactorTableOwner_scatteringfactortable = "\
ScatteringFactorTable object used for a lookup of scattering factors.\n\
This can be also set with the setScatteringFactorTableByType method.\n\
";

const char* doc_ScatteringFactorTableOwner_setScatteringFactorTableByType = "\
Set internal ScatteringFactorTable according to specified string type.\n\
\n\
tp -- string identifier of a registered ScatteringFactorTable type.\n\
Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\
\n\
Deprecated: This method is deprecated and will be removed in the 2.0.0 release.\n\
Use direct assignment to the `scatteringfactortable` property instead, for example:\n\
obj.scatteringfactortable = SFTNeutron()\n\
No return value.\n\
This attribute can be assigned either a ScatteringFactorTable-derived object\n\
or a string name of a registered ScatteringFactorTable class.\n\
Use ScatteringFactorTable.getRegisteredTypes() for a set of registered names.\n\
";

const char* doc_ScatteringFactorTableOwner_getRadiationType = "\
Expand Down Expand Up @@ -318,25 +308,6 @@ ScatteringFactorTablePtr getscatteringfactortable(T& obj)

DECLARE_BYTYPE_SETTER_WRAPPER(setScatteringFactorTable, setscatteringfactortable)

template <class T>
void setscatteringfactortablebytype(T& obj, const std::string& tp)
{
try
{
nb::object warnings = nb::module_::import_("warnings");
nb::object builtins = nb::module_::import_("builtins");
nb::object DeprecationWarning = builtins.attr("DeprecationWarning");
warnings.attr("warn")(
std::string("setScatteringFactorTableByType is deprecated; "
"assign the 'scatteringfactortable' property directly, for example:\n"
"obj.scatteringfactortable = SFTNeutron()"),
DeprecationWarning,
2);
}
catch (...) { /* don't let warnings break the binding */ }
obj.setScatteringFactorTableByType(tp);
}

template <class T>
std::string getradiationtype(T& obj)
{
Expand Down Expand Up @@ -383,10 +354,6 @@ C& wrap_PDFCommon(C& cls)
getscatteringfactortable<W>,
setscatteringfactortable<W, ScatteringFactorTable>,
doc_ScatteringFactorTableOwner_scatteringfactortable)
.def("setScatteringFactorTableByType",
setscatteringfactortablebytype<W>,
nb::arg("tp"),
doc_ScatteringFactorTableOwner_setScatteringFactorTableByType)
.def("getRadiationType",
getradiationtype<W>,
doc_ScatteringFactorTableOwner_getRadiationType)
Expand Down
37 changes: 3 additions & 34 deletions src/extensions/wrap_ScatteringFactorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,9 @@ Base class for classes that own ScatteringFactorTable instance.\n\

const char* doc_ScatteringFactorTableOwner_scatteringfactortable = "\
ScatteringFactorTable object used for a lookup of scattering factors.\n\
This can be also set with the setScatteringFactorTableByType method.\n\
";

const char* doc_ScatteringFactorTableOwner_setScatteringFactorTableByType = "\
Set internal ScatteringFactorTable according to specified string type.\n\
\n\
tp -- string identifier of a registered ScatteringFactorTable type.\n\
Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\
\n\
Deprecated: This method is deprecated and will be removed in the 2.0.0 release.\n\
Use direct assignment to the `scatteringfactortable` property instead, for example:\n\
obj.scatteringfactortable = SFTNeutron()\n\
No return value.\n\
This attribute can be assigned either a ScatteringFactorTable-derived object\n\
or a string name of a registered ScatteringFactorTable class.\n\
Use ScatteringFactorTable.getRegisteredTypes() for a set of registered names.\n\
";

const char* doc_ScatteringFactorTableOwner_getRadiationType = "\
Expand Down Expand Up @@ -454,27 +444,6 @@ void wrap_ScatteringFactorTable(nb::module_& m)
getsftable,
setsftable<ScatteringFactorTableOwner,ScatteringFactorTable>,
doc_ScatteringFactorTableOwner_scatteringfactortable)
// deprecated: prefer assigning the `scatteringfactortable` property
.def("setScatteringFactorTableByType",
+[](SFTOwner& obj, const std::string& tp)
{
try
{
nb::object warnings = nb::module_::import_("warnings");
nb::object builtins = nb::module_::import_("builtins");
nb::object DeprecationWarning = builtins.attr("DeprecationWarning");
warnings.attr("warn")(
std::string("setScatteringFactorTableByType is deprecated; "
"assign the 'scatteringfactortable' property directly, for example:\n"
"obj.scatteringfactortable = SFTNeutron()"),
DeprecationWarning,
2);
}
catch (...) { /* don't let warnings break the binding */ }
obj.setScatteringFactorTableByType(tp);
},
nb::arg("tp"),
doc_ScatteringFactorTableOwner_setScatteringFactorTableByType)
.def("getRadiationType",
[](const SFTOwner &obj)
{
Expand Down
23 changes: 1 addition & 22 deletions tests/test_debyepdfcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pickle
import unittest
import warnings

import numpy
from testutils import _maxNormDiff, loadDiffPyStructure, pickle_with_attr
Expand Down Expand Up @@ -142,28 +141,8 @@ def test_partial_pdfs(self):

def test_pickling(self):
"""Check pickling and unpickling of PDFCalculator."""
# New syntax: assign an SFT instance to the property (should not warn)
dpdfc = self.dpdfc
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
dpdfc.scatteringfactortable = SFTNeutron()
self.assertFalse(
any(isinstance(x.message, DeprecationWarning) for x in w)
)

dpdfc.scatteringfactortable.setCustomAs("Na", "Na", 7)
spkl = pickle.dumps(dpdfc)
dpdfc1_new = pickle.loads(spkl)
self.assertEqual(
dpdfc.scatteringfactortable.type(),
dpdfc1_new.scatteringfactortable.type(),
)
self.assertEqual(7.0, dpdfc1_new.scatteringfactortable.lookup("Na"))

# Old syntax: call the deprecated method (should warn)
dpdfc = self.dpdfc
with self.assertWarns(DeprecationWarning):
dpdfc.setScatteringFactorTableByType("N")
dpdfc.scatteringfactortable = SFTNeutron()
dpdfc.scatteringfactortable.setCustomAs("Na", "Na", 7)
dpdfc.addEnvelope("sphericalshape")
dpdfc.debyeprecision = 0.001
Expand Down
Loading