Description
After upgrading nolds from 0.5.x to 0.6.3, importing the package fails with:
TypeError: 'nolds.datasets' is not a package
Environment
- Python: 3.11
- nolds version: 0.6.3
- OS: macOS (also likely affects Linux/Windows)
Steps to Reproduce
Traceback
File ".../nolds/__init__.py", line 5, in <module>
from .datasets import brown72, tent_map, logistic_map, fbm, fgn, qrandom, \
File ".../nolds/datasets.py", line 467, in <module>
brown72 = load_brown72()
File ".../nolds/datasets.py", line 162, in load_brown72
with resources.files(__name__).joinpath(fname).open('rb') as f:
^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../importlib/resources/_common.py", line 55, in get_package
raise TypeError(f'{package!r} is not a package')
TypeError: 'nolds.datasets' is not a package
Root Cause
In datasets.py, the importlib.resources.files() call uses __name__:
# Line 162
with resources.files(__name__).joinpath(fname).open('rb') as f:
Here, __name__ evaluates to 'nolds.datasets', which is a module (the file datasets.py), not a package.
importlib.resources.files() requires a package (a directory with __init__.py), not a module.
Package Structure
nolds/
├── __init__.py ← 'nolds' is a package ✓
├── datasets.py ← 'nolds.datasets' is a MODULE (not a package!)
├── datasets/ ← Data directory (contains .npy files)
│ ├── brown72.npy
│ └── qrandom.npy
└── ...
Suggested Fix
Change __name__ to the parent package name 'nolds':
# Before (broken)
with resources.files(__name__).joinpath(fname).open('rb') as f:
# After (fixed)
with resources.files('nolds').joinpath(fname).open('rb') as f:
This affects the following functions in datasets.py:
load_qrandom() (line ~147)
load_brown72() (line ~162)
load_lorenz_physionet() (lines ~182, ~185)
Workaround
For now, users can downgrade:
Additional Context
This bug was introduced when migrating from the deprecated pkg_resources to importlib.resources. The old pkg_resources API worked differently and didn't have this module vs. package distinction issue.
Description
After upgrading nolds from 0.5.x to 0.6.3, importing the package fails with:
Environment
Steps to Reproduce
Traceback
Root Cause
In
datasets.py, theimportlib.resources.files()call uses__name__:Here,
__name__evaluates to'nolds.datasets', which is a module (the filedatasets.py), not a package.importlib.resources.files()requires a package (a directory with__init__.py), not a module.Package Structure
Suggested Fix
Change
__name__to the parent package name'nolds':This affects the following functions in
datasets.py:load_qrandom()(line ~147)load_brown72()(line ~162)load_lorenz_physionet()(lines ~182, ~185)Workaround
For now, users can downgrade:
Additional Context
This bug was introduced when migrating from the deprecated
pkg_resourcestoimportlib.resources. The oldpkg_resourcesAPI worked differently and didn't have this module vs. package distinction issue.