Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeWarning: Could not locate the config file. #33

Open
hengee opened this issue Jul 31, 2019 · 2 comments
Open

RuntimeWarning: Could not locate the config file. #33

hengee opened this issue Jul 31, 2019 · 2 comments

Comments

@hengee
Copy link

hengee commented Jul 31, 2019

I have install pylearn-parsimony accordingly but when I run the example code for elastic net:

import parsimony.estimators as estimators
alpha = 0.1  # global penalty
l = 0.1  # l1 ratio (lasso)
enet_estimator = estimators.ElasticNet(l=l, alpha=alpha)
enet_estimator.fit(X, y)
print("Estimated beta error =", np.linalg.norm(enet_estimator.beta - beta))

It then returns:

/usr/local/lib/python3.6/dist-packages/pylearn_parsimony-0.3.1-py3.6.egg/parsimony/config.py:55: RuntimeWarning: Could not locate the config file.
Estimated beta error = 0.8064548347250173
/usr/local/lib/python3.6/dist-packages/pylearn_parsimony-0.3.1-py3.6.egg/parsimony/config.py:66: RuntimeWarning: Could not locate the config file.
@desanou
Copy link

desanou commented Aug 29, 2022

I have the same warning when I import parsimony.estimators. On my side, it only appears during the first import in the python session.

@DimitriPapadopoulos
Copy link
Member

DimitriPapadopoulos commented Aug 29, 2022

The warning is emitted in __init__(), __del__(), or flush(). See for example:

self._ini_file = self._ini_file_name(str(ini_file))
self._config = configparser.ConfigParser()
if os.path.exists(self._ini_file):
try:
self._config.read(self._ini_file)
except configparser.ParsingError:
warnings.warn("Could not parse the config file.",
RuntimeWarning)
else:
warnings.warn("Could not locate the config file.", RuntimeWarning)

I guess something's wrong with self._ini_file = self._ini_file_name(str(ini_file)):

def _ini_file_name(self, ini_file):
"""Extracts the directory of this module.
"""
fname = inspect.currentframe() # This module.
fname = inspect.getfile(fname) # Filename of this module.
fname = os.path.abspath(fname) # Absolute path of this module.
fname = os.path.dirname(fname) # Directory of this module.
if fname[-1] != "/":
fname = fname + "/" # Should be there, but just in case ...
fname = fname + ini_file # The ini file.
return fname

It would help if you could add print statements to find the path of the config file and start investigating why it is missing.

This might be related:

# TODO: Python 3 destroys the ini file sometimes on delete. Make the config
# read the file on every call? Slower, but much safer; especially when
# running multiple instances of pylearn-parsimony.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants