Skip to content

Commit 62d2bcd

Browse files
fix: restore pandas DataFrame type hints in input.py
Use TYPE_CHECKING import for pd so lazy loading stays fast while keeping return type annotations on get_cloud_emissions_data and get_cpu_power_data. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e61c14b commit 62d2bcd

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

codecarbon/input.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
from contextlib import ExitStack
1313
from importlib.resources import as_file as importlib_resources_as_file
1414
from importlib.resources import files as importlib_resources_files
15-
from typing import Any, Dict
15+
from typing import TYPE_CHECKING, Any, Dict
16+
17+
if TYPE_CHECKING:
18+
import pandas as pd
1619

1720
_CACHE: Dict[str, Any] = {}
1821
_MODULE_NAME = "codecarbon"
@@ -144,7 +147,7 @@ def get_global_energy_mix_data(self) -> Dict:
144147
_ensure_static_data_loaded()
145148
return _CACHE["global_energy_mix"]
146149

147-
def get_cloud_emissions_data(self):
150+
def get_cloud_emissions_data(self) -> pd.DataFrame:
148151
"""
149152
Returns Cloud Regions Impact Data.
150153
Data is loaded on first access and cached for all tracker instances.
@@ -192,7 +195,7 @@ def get_carbon_intensity_per_source_data(self) -> Dict:
192195
_ensure_static_data_loaded()
193196
return _CACHE["carbon_intensity_per_source"]
194197

195-
def get_cpu_power_data(self):
198+
def get_cpu_power_data(self) -> pd.DataFrame:
196199
"""
197200
Returns CPU power Data.
198201
Data is loaded on first access and cached for all tracker instances.

0 commit comments

Comments
 (0)