Skip to content

Commit 35cdfc3

Browse files
committed
use pathlib in example.py module
1 parent 0729083 commit 35cdfc3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

larray/example.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import os
2+
from pathlib import Path
3+
24
import larray as la
35

46

5-
_TEST_DIR = os.path.join(os.path.dirname(__file__), 'tests')
7+
_TEST_DIR = Path(__file__).parent / 'tests'
68

7-
EXAMPLE_FILES_DIR = os.path.join(_TEST_DIR, 'data')
9+
EXAMPLE_FILES_DIR = _TEST_DIR / 'data'
810
AVAILABLE_EXAMPLE_DATA = {
9-
'demography': os.path.join(EXAMPLE_FILES_DIR, 'demography.h5'),
10-
'demography_eurostat': os.path.join(EXAMPLE_FILES_DIR, 'demography_eurostat.h5')
11+
'demography': EXAMPLE_FILES_DIR / 'demography.h5',
12+
'demography_eurostat': EXAMPLE_FILES_DIR / 'demography_eurostat.h5'
1113
}
12-
EXAMPLE_EXCEL_TEMPLATES_DIR = os.path.join(_TEST_DIR, 'excel_template')
14+
EXAMPLE_EXCEL_TEMPLATES_DIR = _TEST_DIR / 'excel_template'
1315

1416

15-
def get_example_filepath(fname):
17+
def get_example_filepath(fname) -> Path:
1618
r"""Return absolute path to an example file if exist.
1719
1820
Parameters
@@ -33,8 +35,8 @@ def get_example_filepath(fname):
3335
--------
3436
>>> fpath = get_example_filepath('examples.xlsx')
3537
"""
36-
fpath = os.path.abspath(os.path.join(EXAMPLE_FILES_DIR, fname))
37-
if not os.path.exists(fpath):
38+
fpath = (EXAMPLE_FILES_DIR / fname).absolute()
39+
if not fpath.exists():
3840
AVAILABLE_EXAMPLE_FILES = os.listdir(EXAMPLE_FILES_DIR)
3941
raise ValueError(f"Example file {fname} does not exist. "
4042
f"Available example files are: {AVAILABLE_EXAMPLE_FILES}")

0 commit comments

Comments
 (0)