Skip to content

Commit d6992e6

Browse files
authored
Merge pull request #372 from sbillinge/depr-tests
depr tests
2 parents c357d3e + 7ac6862 commit d6992e6

File tree

11 files changed

+349
-207
lines changed

11 files changed

+349
-207
lines changed

docs/source/examples/parsers_example.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ Using the parsers module, we can load file data into simple and easy-to-work-wit
1313
Our goal will be to extract the data, and the parameters listed in the header, from this file and
1414
load it into our program.
1515

16-
2) To get the data table, we will use the ``loadData`` function. The default behavior of this
16+
2) To get the data table, we will use the ``load_data`` function. The default behavior of this
1717
function is to find and extract a data table from a file.
1818

1919
.. code-block:: python
2020
21-
from diffpy.utils.parsers.loaddata import loadData
22-
data_table = loadData('<PATH to data.txt>')
21+
from diffpy.utils.parsers import load_data
22+
data_table = load_data('<PATH to data.txt>')
2323
2424
While this will work with most datasets, on our ``data.txt`` file, we got a ``ValueError``. The reason for this is
2525
due to the comments ``$ Phase Transition Near This Temperature Range`` and ``--> Note Significant Jump in Rw <--``
2626
embedded within the dataset. To fix this, try using the ``comments`` parameter.
2727

2828
.. code-block:: python
2929
30-
data_table = loadData('<PATH to data.txt>', comments=['$', '-->'])
30+
data_table = load_data('<PATH to data.txt>', comments=['$', '-->'])
3131
32-
This parameter tells ``loadData`` that any lines beginning with ``$`` and ``-->`` are just comments and
32+
This parameter tells ``load_data`` that any lines beginning with ``$`` and ``-->`` are just comments and
3333
more entries in our data table may follow.
3434

3535
Here are a few other parameters to test out:
@@ -39,30 +39,30 @@ Here are a few other parameters to test out:
3939

4040
.. code-block:: python
4141
42-
loadData('<PATH to data.txt>', comments=['$', '-->'], delimiter=',')
42+
load_data('<PATH to data.txt>', comments=['$', '-->'], delimiter=',')
4343
4444
returns an empty list.
4545
* ``minrows=50``: Only look for data tables with at least 50 rows. Since our data table has much less than that many
4646
rows, running
4747

4848
.. code-block:: python
4949
50-
loadData('<PATH to data.txt>', comments=['$', '-->'], minrows=50)
50+
load_data('<PATH to data.txt>', comments=['$', '-->'], minrows=50)
5151
5252
returns an empty list.
5353
* ``usecols=[0, 3]``: Only return the 0th and 3rd columns (zero-indexed) of the data table. For ``data.txt``, this
5454
corresponds to the temperature and rw columns.
5555

5656
.. code-block:: python
5757
58-
loadData('<PATH to data.txt>', comments=['$', '-->'], usecols=[0, 3])
58+
load_data('<PATH to data.txt>', comments=['$', '-->'], usecols=[0, 3])
5959
60-
3) Next, to get the header information, we can again use ``loadData``,
60+
3) Next, to get the header information, we can again use ``load_data``,
6161
but this time with the ``headers`` parameter enabled.
6262

6363
.. code-block:: python
6464
65-
hdata = loadData('<PATH to data.txt>', comments=['$', '-->'], headers=True)
65+
hdata = load_data('<PATH to data.txt>', comments=['$', '-->'], headers=True)
6666
6767
4) Rather than working with separate ``data_table`` and ``hdata`` objects, it may be easier to combine them into a single
6868
dictionary. We can do so using the ``serialize_data`` function.
@@ -116,8 +116,8 @@ The returned value, ``parsed_file_data``, is the dictionary we just added to ``s
116116

117117
.. code-block:: python
118118
119-
data_table = loadData('<PATH to moredata.txt>')
120-
hdata = loadData('<PATH to moredata.txt>', headers=True)
119+
data_table = load_data('<PATH to moredata.txt>')
120+
hdata = load_data('<PATH to moredata.txt>', headers=True)
121121
serialize_data('<PATH to moredata.txt>', hdata, data_table, serial_file='<PATH to serialdata.json>')
122122
123123
The serial file ``serialfile.json`` should now contain two entries: ``data.txt`` and ``moredata.txt``.

docs/source/examples/resample_example.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ given enough datapoints.
1616

1717
.. code-block:: python
1818
19-
from diffpy.utils.parsers.loaddata import loadData
20-
nickel_datatable = loadData('<PATH to Nickel.gr>')
21-
nitarget_datatable = loadData('<PATH to NiTarget.gr>')
19+
from diffpy.utils.parsers import load_data
20+
nickel_datatable = load_data('<PATH to Nickel.gr>')
21+
nitarget_datatable = load_data('<PATH to NiTarget.gr>')
2222
2323
Each data table has two columns: first is the grid and second is the function value.
2424
To extract the columns, we can utilize the serialize function ...

docs/source/utilities/parsers_utility.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Parsers Utility
55

66
The ``diffpy.utils.parsers`` module allows users to easily and robustly load file data into a Python project.
77

8-
- ``loaddata.loadData()``: Find and load a data table/block from a text file. This seems to work for most datafiles
8+
- ``loaddata.load_data()``: Find and load a data table/block from a text file. This seems to work for most datafiles
99
including those generated by diffpy programs. Running only ``numpy.loadtxt`` will result in errors
1010
for most these files as there is often excess data or parameters stored above the data block.
1111
Users can instead choose to load all the parameters of the form ``<param_name> = <param_value>`` into a dictionary
@@ -17,7 +17,7 @@ The ``diffpy.utils.parsers`` module allows users to easily and robustly load fil
1717
- ``serialization.deserialize_data()``: Load data from a serial file format into a Python dictionary. Currently, the only supported
1818
serial format is ``.json``.
1919

20-
- ``serialization.serialize_data()``: Serialize the data generated by ``loadData()`` into a serial file format. Currently, the only
20+
- ``serialization.serialize_data()``: Serialize the data generated by ``load_data()`` into a serial file format. Currently, the only
2121
supported serial format is ``.json``.
2222

2323
For a more in-depth tutorial for how to use these parser utilities, click :ref:`here <Parsers Example>`.

news/depr-tests.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* load_data now takes a Path or a string for the file-path
8+
9+
**Deprecated:**
10+
11+
* diffpy.utils.parsers.loaddata.loadData replaced by diffpy.utils.parsers.load_data
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/utils/_deprecator.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def deprecated(message, *, category=DeprecationWarning, stacklevel=1):
2020
2121
.. code-block:: python
2222
23-
from diffpy._deprecations import deprecated
23+
from diffpy.utils._deprecator import deprecated
2424
import warnings
2525
2626
@deprecated("old_function is deprecated; use new_function instead")
@@ -39,7 +39,6 @@ def new_function(x, y):
3939
.. code-block:: python
4040
4141
from diffpy._deprecations import deprecated
42-
import warnings
4342
4443
warnings.simplefilter("always", DeprecationWarning)
4544
@@ -83,7 +82,9 @@ def wrapper(*args, **kwargs):
8382
return decorator
8483

8584

86-
def deprecation_message(base, old_name, new_name, removal_version):
85+
def deprecation_message(
86+
base, old_name, new_name, removal_version, new_base=None
87+
):
8788
"""Generate a deprecation message.
8889
8990
Parameters
@@ -102,7 +103,17 @@ def deprecation_message(base, old_name, new_name, removal_version):
102103
str
103104
A formatted deprecation message.
104105
"""
106+
if new_base is None:
107+
new_base = base
105108
return (
106109
f"'{base}.{old_name}' is deprecated and will be removed in "
107-
f"version {removal_version}. Please use '{base}.{new_name}' instead."
110+
f"version {removal_version}. Please use '{new_base}.{new_name}' "
111+
f"instead."
108112
)
113+
114+
115+
_DEPRECATION_DOCSTRING_TEMPLATE = (
116+
"This function has been deprecated and will be "
117+
"removed in version {removal_version}. Please use"
118+
"{new_base}.{new_name} instead."
119+
)

src/diffpy/utils/parsers/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
# (c) 2010 The Trustees of Columbia University
77
# in the City of New York. All rights reserved.
88
#
9-
# File coded by: Chris Farrow
9+
# File coded by: Simon Billinge
1010
#
1111
# See AUTHORS.txt for a list of people who contributed.
1212
# See LICENSE_DANSE.txt for license information.
1313
#
1414
##############################################################################
1515
"""Various utilities related to data parsing and manipulation."""
16+
17+
# this allows load_data to be imported from diffpy.utils.parsers
18+
# it is needed during deprecation of the old loadData structure
19+
# when we remove loadData we can move all the parser functionality
20+
# a parsers.py module (like tools.py) and remove this if we want
21+
from .loaddata import load_data
22+
23+
__all__ = ["load_data"]

0 commit comments

Comments
 (0)