pythermalcomfort
pythermalcomfort copied to clipboard
pythermalcomfort 2.8.4 or 2.8.3 --> mutable default <class 'numpy.ndarray'> for field local_bsa is not allowed: use default_factory
Hi. This is my first comment. I'm not sure if I'm posting in the right place. I apologize in advance if I'm making a mistake.
When I run below code (or any code with pythermalcomfort)
from pythermalcomfort.models import pmv_ppd
results = pmv_ppd(tdb=22, tr=22, vr=0.1, rh=60, met=1, clo=0.9, standard="ASHRAE")
print(results)
I got the below output;
Traceback (most recent call last):
from pythermalcomfort.models import pmv_ppd
File "AppData\Local\Programs\Python\Python311\Lib\site-packages\pythermalcomfort\__init__.py", line 3, in <module>
from pythermalcomfort.models import *
File "AppData\Local\Programs\Python\Python311\Lib\site-packages\pythermalcomfort\models.py", line 28, in <module>
from pythermalcomfort.jos3_functions import thermoregulation as threg
File "AppData\Local\Programs\Python\Python311\Lib\site-packages\pythermalcomfort\jos3_functions\thermoregulation.py", line 17, in <module>
from pythermalcomfort.jos3_functions import construction as cons
File "AppData\Local\Programs\Python\Python311\Lib\site-packages\pythermalcomfort\jos3_functions\construction.py", line 16, in <module>
from pythermalcomfort.jos3_functions.parameters import Default
File "AppData\Local\Programs\Python\Python311\Lib\site-packages\pythermalcomfort\jos3_functions\parameters.py", line 20, in <module>
@dataclass
^^^^^^^^^
File "AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1230, in dataclass
return wrap(cls)
^^^^^^^^^
File "AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 1220, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 958, in _process_class
cls_fields.append(_get_field(cls, name, type, kw_only))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "AppData\Local\Programs\Python\Python311\Lib\dataclasses.py", line 815, in _get_field
raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'numpy.ndarray'> for field local_bsa is not allowed: use default_factory
When pythermalcomfort version is 2.8.4 or 2.8.3 this error occurs. 2.8.2 and 2.8.1 no issue.
Desktop
- OS: Windows 10 Enterprise 19045.3448
- Visual Studio Code: 1.83.0
- Interpreter: Python 3.11.6 x64
Normally, I was using version pythermalcomfort 2.8.1, but when I looked to check for the latest updates and installed the new version, I encountered this error. The latest version where I do not get any errors is 2.8.2.
Additionally, if you are using Python 3.12.0 version, pythermalcomfort is not installed. This is a different error. I removed python 3.12.0 and install 3.11.6. This is a completely independent and different error from above, I just mentioned it as additional information.
Python 3.11 and 3.12 are not yet supported in pythermalcomfort.
Python 3.10
Thank you very much for reporting this issue. I have created a new virtual environment using Python 3.10 and then installed pythermalcomfort with this command:
pip install pythermalcomfort
This installs pythermalcomfort-2.8.4. However, I did not get any error after running the following code:
from pythermalcomfort.models import pmv_ppd
results = pmv_ppd(tdb=22, tr=22, vr=0.1, rh=60, met=1, clo=0.9, standard="ASHRAE")
print(results)
Python 3.12
I created a virtual environment with Python 3.12 and I confirm that I also cannot install pythermalcomfort.
Python 3.11
I created a virtual environment with Python 3.11 and I confirm that I am getting the same error as you.
I, therefore, suggest that you use Python 3.10 while I find a solution to the problem. I hope this works for you and this is not causing too many issues.
I believe I was able to fix this issue and in the future pythermalcomfort should be compatible with version 3.11. I am tagging @AkihisaNomoto who wrote the dataclass code.
Aki, I fixed the issue by changing the code as follows:
from typing import ClassVar
import numpy as np
@dataclass(frozen=True)
class Default:
# Body information
height: float = 1.72 # [m]
weight: float = 74.43 # [kg]
age: int = 20 # [-]
body_fat: float = 15 # [%]
cardiac_index: float = 2.59 # [L/min/m2]
blood_flow_rate: int = 290 # [L/h]
physical_activity_ratio: float = 1.25 # [-]
metabolic_rate: float = 1.0 # [met]
sex: str = "male"
posture: str = "standing"
bmr_equation: str = "harris-benedict"
bsa_equation: str = "dubois"
local_bsa: ClassVar[list[float]] = np.array(
[
0.110,
0.029,
0.175,
0.161,
0.221,
0.096,
0.063,
0.050,
0.096,
0.063,
0.050,
0.209,
0.112,
0.056,
0.209,
0.112,
0.056,
]
)
# Environment information
core_temperature: float = 37 # [°C]
skin_temperature: float = 34 # [°C]
other_body_temperature: float = 36 # [°C]
dry_bulb_air_temperature: float = 28.8 # [°C]
mean_radiant_temperature: float = 28.8 # [°C]
relative_humidity: float = 50 # [%]
air_speed: float = 0.1 # [m/s]
# Clothing information
clothing_insulation: float = 0 # [clo]
clothing_vapor_permeation_efficiency: float = 0.45 # [-]
lewis_rate = 16.5 # [K/kPa]