Closed ZhelunChen closed 1 year ago
thanks @ZhelunChen. I have provided a fix for the error on line 75: https://github.com/HichamJohra/energy_flexibility_kpis/commit/2e68f5083d8736bf5fb70a2c52a2c0ef395e432f
Please, can you point me to the module you are running that is failing on line 9?
@kingsleynweye The test module I developed is the test_kpi.py file in the /test subfolder. I think hicham just merged it to the develop branch. I was not able to call the function successfully with line 9 enable.
@kingsleynweye The test module I developed is the test_kpi.py file in the /test subfolder. I think hicham just merged it to the develop branch. I was not able to call the function successfully with line 9 enable.
Okay, I see it now. I think it might be a thing of how you are calling the tests. Are you calling it like:
python -m unittest
@kingsleynweye ah, you are right. Thanks!
@kingsleynweye Sorry, I thought that was the issue, but it wasn't after testing it. I try in both cmd and my anonconda environment, get the same error.
ImportError: Failed to import test module: test_kpi
Traceback (most recent call last):
File "C:\Users\zhelu\AppData\Local\Programs\Python\Python311\Lib\unittest\loader.py", line 154, in loadTestsFromName
module = import(module_name)
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test\test_kpi.py", line 11, in
Ran 1 test in 0.000s
FAILED (errors=1)
@kingsleynweye Sorry, I thought that was the issue, but it wasn't after testing it. I try in both cmd and my anonconda environment, get the same error.
D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test>python -m unittest test_kpi
E
ERROR: test_kpi (unittest.loader._FailedTest.test_kpi)
ImportError: Failed to import test module: test_kpi Traceback (most recent call last): File "C:\Users\zhelu\AppData\Local\Programs\Python\Python311\Lib\unittest\loader.py", line 154, in loadTestsFromName module = import(module_name) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\test\test_kpi.py", line 11, in import kpi File "D:\repo\contribute_energy_flexibility_kpis\develop_test\energy_flexibility_kpis\kpi.py", line 9, in from energy_flexibility_kpis.utilities import Parser ModuleNotFoundError: No module named 'energy_flexibility_kpis'
Ran 1 test in 0.000s
FAILED (errors=1)
What is the cmd you are executing? It runs fine on my end after I fix the filepath error for data1_simple
by supplying the absolute filepath to data1_simple.csv
in pd.read_csv
. This is what I get:
(env) kingsleyenweye@MacBook-Pro-5 contribute-energy_flexibility_kpis % python -m unittest
.
----------------------------------------------------------------------
Ran 1 test in 0.006s
OK
I am running the command from the root of the repository.
@kingsleynweye Thanks! I've updated the filepath to data1_simple.csv
to match the location of the 'test_kpi.py' file, so it can be run from any directory. This change is available in the most recent commit 7995b08755e0db39ec580c6b625d8af341f8a6af. While I have no further issue calling kpi.py, I recommend updating the import method to ensure that 'kpi.py' can be called from any working directory in the future for others sake.
@kingsleynweye Thanks! I've updated the filepath to
data1_simple.csv
to match the location of the 'test_kpi.py' file, so it can be run from any directory. This change is available in the most recent commit 7995b08. While I have no further issue calling kpi.py, I recommend updating the import method to ensure that 'kpi.py' can be called from any working directory in the future for others sake.
Thanks @ZhelunChen and I see what you mean. The way python describes importing package modules is in the form:
import package_name.module_name
Another example is in the pandas source code, which is the format I adopted in line 9.
I think the thing to be aware of is that when a package is pip installed, it will be executed from the root path which is why file and module paths have to be defined in absolute form from that location.
@kingsleynweye
line 9 of kpi.py causing error - ModuleNotFoundError: No module named 'energy_flexibility_kpis'
flexibility_factor always return -1, probably because an error on line 75. should probably use "|" instead of "&"