Skip to content

Commit 65f2cf2

Browse files
authored
Merge pull request #216 from cadenmyers13/load-data
fix: load runtime data using `importlib.resources.files`
2 parents 8bf3d8e + 19dfb62 commit 65f2cf2

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

news/load-data.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: change how data path is referenced. Remove ``__file__`` reference.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ include = ["*"] # package names should match these glob patterns (["*"] by defa
5454
exclude = ["diffpy.labpdfproc.tests*"] # exclude packages matching these glob patterns (empty by default)
5555
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
5656

57+
[tool.setuptools.package-data]
58+
"diffpy.labpdfproc" = ["data/*"]
59+
5760
[tool.setuptools.dynamic]
5861
dependencies = {file = ["requirements/pip.txt"]}
5962

src/diffpy/labpdfproc/functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import math
22
import warnings
3-
from pathlib import Path
3+
from importlib.resources import files
44

55
import numpy as np
66
import pandas as pd
@@ -17,11 +17,11 @@
1717
CVE_METHODS = ["brute_force", "polynomial_interpolation"]
1818

1919
# Pre-computed datasets for polynomial interpolation (fast calculation)
20+
data_dir = files("diffpy.labpdfproc") / "data"
2021
MUD_LIST = np.array([0.5, 1, 2, 3, 4, 5, 6, 7])
21-
CWD = Path(__file__).parent.resolve()
22-
MULS = np.loadtxt(CWD / "data" / "inverse_cve.xy")
22+
MULS = np.loadtxt(data_dir / "inverse_cve.xy")
2323
COEFFICIENT_LIST = np.array(
24-
pd.read_csv(CWD / "data" / "coefficient_list.csv", header=None)
24+
pd.read_csv(data_dir / "coefficient_list.csv", header=None)
2525
)
2626
INTERPOLATION_FUNCTIONS = [
2727
interp1d(MUD_LIST, coeffs, kind="quadratic") for coeffs in COEFFICIENT_LIST

0 commit comments

Comments
 (0)