Skip to content

Commit

Permalink
Merge branch 'lmfit:master' into add-vscode-settings-to-gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
willynilly authored Apr 3, 2024
2 parents 61f093d + 57e2a20 commit cebb494
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 709 deletions.
43 changes: 0 additions & 43 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,49 +247,6 @@ total). :mod:`uncertainties` is thus a **lightweight, portable
package** with abundant documentation and tests.


Migration from version 1 to version 2
=====================================

Some **incompatible changes** were introduced in version 2 of
:mod:`uncertainties` (see the `version history`_). While the version 2
line will support the version 1 syntax for some time, it is
recommended to **update existing programs** as soon as possible. This
can be made easier through the provided **automatic updater**.

The automatic updater works like Python's `2to3
<http://docs.python.org/2/library/2to3.html>`_ updater. It can be run
(in a Unix or DOS shell) with:

.. code-block:: sh
python -m uncertainties.1to2
For example, updating a single Python program can be done with

.. code-block:: sh
python -m uncertainties.1to2 -w example.py
All the Python programs contained under a directory ``Programs``
(including in nested sub-directories) can be automatically updated
with

.. code-block:: sh
python -m uncertainties.1to2 -w Programs
Backups are automatically created, unless the ``-n`` option is given.

Some **manual adjustments** might be necessary after running the
updater (incorrectly modified lines, untouched obsolete syntax).

While the updater creates backup copies by default, it is generally
useful to **first create a backup** of the modified directory, or
alternatively to use some `version control
<http://en.wikipedia.org/wiki/Version_control_system>`_
system. Reviewing the modifications with a `file comparison tool
<http://en.wikipedia.org/wiki/File_comparison>`_ might also be useful.

What others say
===============

Expand Down
19 changes: 0 additions & 19 deletions uncertainties/1to2.py

This file was deleted.

82 changes: 3 additions & 79 deletions uncertainties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,6 @@ def set_doc_string(func):
CONSTANT_TYPES = FLOAT_LIKE_TYPES+(complex,)

###############################################################################

# Utility for issuing deprecation warnings

def deprecation(message):
'''
Warn the user with the given message, by issuing a
DeprecationWarning.
'''

# stacklevel = 3 points to the original user call (not to the
# function from this module that called deprecation()).
# DeprecationWarning is ignored by default: not used.

warnings.warn('Obsolete: %s Code can be automatically updated with'
' python -m uncertainties.1to2 -w ProgramDirectory.'
% message, stacklevel=3)

###############################################################################

## Definitions that depend on the availability of NumPy:


Expand Down Expand Up @@ -934,21 +915,6 @@ def PDG_precision(std_dev):
# used instead of the % formatting operator, if available:
robust_format = format

class CallableStdDev(float):
'''
Class for standard deviation results, which used to be
callable. Provided for compatibility with old code. Issues an
obsolescence warning upon call.
'''

# This class is a float. It must be set to the standard deviation
# upon construction.

def __call__ (self):
deprecation('the std_dev attribute should not be called'
' anymore: use .std_dev instead of .std_dev().')
return self

# Exponent letter: the keys are the possible main_fmt_type values of
# format_num():
EXP_LETTERS = {'f': 'e', 'F': 'E'}
Expand Down Expand Up @@ -1843,7 +1809,7 @@ def std_dev(self):
#std_dev value (in fact, many intermediate AffineScalarFunc do
#not need to have their std_dev calculated: only the final
#AffineScalarFunc returned to the user does).
return CallableStdDev(sqrt(sum(
return float(sqrt(sum(
delta**2 for delta in self.error_components().values())))

# Abbreviation (for formulas, etc.):
Expand Down Expand Up @@ -2798,13 +2764,7 @@ def std_dev(self, std_dev):
if std_dev < 0 and not isinfinite(std_dev):
raise NegativeStdDev("The standard deviation cannot be negative")

self._std_dev = CallableStdDev(std_dev)

# Support for legacy method:
def set_std_dev(self, value): # Obsolete
deprecation('instead of set_std_dev(), please use'
' .std_dev = ...')
self.std_dev = value
self._std_dev = float(std_dev)

# The following method is overridden so that we can represent the tag:
def __repr__(self):
Expand Down Expand Up @@ -3263,21 +3223,9 @@ def ufloat(nominal_value, std_dev=None, tag=None):
"""
Return a new random variable (Variable object).
The only non-obsolete use is:
- ufloat(nominal_value, std_dev),
- ufloat(nominal_value, std_dev, tag=...).
Other input parameters are temporarily supported:
- ufloat((nominal_value, std_dev)),
- ufloat((nominal_value, std_dev), tag),
- ufloat(str_representation),
- ufloat(str_representation, tag).
Valid string representations str_representation are listed in
the documentation for ufloat_fromstr().
nominal_value -- nominal value of the random variable. It is more
meaningful to use a value close to the central value or to the
mean. This value is propagated by mathematical operations as if it
Expand All @@ -3292,28 +3240,4 @@ def ufloat(nominal_value, std_dev=None, tag=None):
error_components() method).
"""

try:
# Standard case:
return Variable(nominal_value, std_dev, tag=tag)
# Exception types raised by, respectively: tuple or string that
# can be converted through float() (case of a number with no
# uncertainty), and string that cannot be converted through
# float():
except (TypeError, ValueError):

if tag is not None:
tag_arg = tag # tag keyword used:
else:
tag_arg = std_dev # 2 positional arguments form

try:
final_ufloat = ufloat_obsolete(nominal_value, tag_arg)
except: # The input is incorrect, not obsolete
raise
else:
# Obsolete, two-argument call:
deprecation(
'either use ufloat(nominal_value, std_dev),'
' ufloat(nominal_value, std_dev, tag), or the'
' ufloat_fromstr() function, for string representations.')
return final_ufloat
return Variable(nominal_value, std_dev, tag=tag)
Empty file removed uncertainties/lib1to2/__init__.py
Empty file.
Empty file.
38 changes: 0 additions & 38 deletions uncertainties/lib1to2/fixes/fix_std_dev.py

This file was deleted.

22 changes: 0 additions & 22 deletions uncertainties/lib1to2/fixes/fix_std_devs.py

This file was deleted.

80 changes: 0 additions & 80 deletions uncertainties/lib1to2/fixes/fix_uarray_umatrix.py

This file was deleted.

Loading

0 comments on commit cebb494

Please sign in to comment.