Skip to content

Commit a6ddd06

Browse files
authored
Merge pull request #377 from cadenmyers13/import-bug
V3.7.0
2 parents bfaea66 + efd094d commit a6ddd06

File tree

16 files changed

+427
-230
lines changed

16 files changed

+427
-230
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/dep-msg-helper.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**Added:**
22

3-
* Add ``deprecation_message`` helper for printing consistent deprecation messages.
3+
* Add ``build_deprecation_message`` helper for printing consistent deprecation messages.
4+
* Add ``generate_deprecation_docstring`` for generating a template docstring for deprecated functions.
5+
46

57
**Changed:**
68

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>

news/deprecator.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
**Added:**
22

3-
* added a function in _deprecator to generate a deprecation message for copy pasting
43
* Add ``@deprecated`` decorator.
54

65
**Changed:**

news/python-version.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Support for Python 3.14
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* Support for Python 3.11
16+
17+
**Fixed:**
18+
19+
* All references to ``loadData`` changed to ``load_data`` due to that deprecation
20+
21+
**Security:**
22+
23+
* <news item>

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ maintainers = [
1414
description = "General utilities for analyzing diffraction data"
1515
keywords = ['text data parsers', 'wx grid', 'diffraction objects']
1616
readme = "README.rst"
17-
requires-python = ">=3.11, <3.14"
17+
requires-python = ">=3.12, <3.15"
1818
classifiers = [
1919
'Development Status :: 5 - Production/Stable',
2020
'Environment :: Console',
@@ -25,9 +25,9 @@ classifiers = [
2525
'Operating System :: Microsoft :: Windows',
2626
'Operating System :: POSIX',
2727
'Operating System :: Unix',
28-
'Programming Language :: Python :: 3.11',
2928
'Programming Language :: Python :: 3.12',
3029
'Programming Language :: Python :: 3.13',
30+
'Programming Language :: Python :: 3.14',
3131
'Topic :: Scientific/Engineering :: Physics',
3232
'Topic :: Scientific/Engineering :: Chemistry',
3333
]

src/diffpy/utils/_deprecator.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def deprecated(message, *, category=DeprecationWarning, stacklevel=1):
2020
2121
.. code-block:: python
2222
23-
from diffpy.utils._deprecator import deprecated, deprecation_message
23+
from diffpy.utils._deprecator import (
24+
deprecated, build_deprecation_message
25+
)
2426
2527
deprecation_warning = build_deprecation_message("diffpy.utils",
2628
"old_function",
@@ -44,8 +46,9 @@ def new_function(x, y):
4446
4547
.. code-block:: python
4648
47-
from diffpy.utils._deprecator import deprecated, deprecation_message
48-
49+
from diffpy.utils._deprecator import (
50+
deprecated, build_deprecation_message
51+
)
4952
deprecation_warning = build_deprecation_message("diffpy.utils",
5053
"OldAtom",
5154
"NewAtom",
@@ -136,35 +139,36 @@ def build_deprecation_message(
136139
def generate_deprecation_docstring(new_name, removal_version, new_base=None):
137140
"""Generate a docstring for copy-pasting into a deprecated function.
138141
139-
this function will print the text to the terminal for copy-pasting
140-
141-
usage:
142-
python
143-
>>> import diffpy.utils._deprecator.generate_deprecation_docstring as gdd
144-
>>> gdd("new_name", "4.0.0")
145-
146-
The message looks like:
147-
This function has been deprecated and will be removed in version
148-
{removal_version}. Please use {new_base}.{new_name} instead.
142+
This function will print the text to the terminal for copy-pasting.
149143
150144
Parameters
151145
----------
152-
new_name: str
153-
The name of the new function or class to replace the existing one
154-
removal_version: str
146+
new_name : str
147+
The name of the new function or class to replace the existing one.
148+
removal_version : str
155149
The version when the deprecated item is targeted for removal,
156-
e.g., 4.0.0
157-
new_base: str Optional. Defaults to old_base.
158-
The new base for importing. The new import statement would look like
159-
"from new_base import new_name"
150+
e.g., 4.0.0.
151+
new_base : str, optional
152+
The new base for importing. The new import statement would look like
153+
"from new_base import new_name". Defaults to None.
154+
155+
Example
156+
-------
157+
>>> from diffpy.utils._deprecator import generate_deprecation_docstring
158+
>>> generate_deprecation_docstring("new_name", "4.0.0")
159+
160+
The message looks like:
161+
This function has been deprecated and will be removed in version
162+
{removal_version}. Please use {new_base}.{new_name} instead.
163+
160164
161165
Returns
162166
-------
163167
None
164168
"""
165169
print(
166-
f"This function has been deprecated and will be "
167-
f"removed in version {removal_version}. Please use"
168-
f"{new_base}.{new_name} instead."
170+
f"This function has been deprecated and will be removed in version "
171+
f"{removal_version}.\n"
172+
f"Please use {new_base}.{new_name} instead."
169173
)
170174
return

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)