Skip to content

Commit e5e12e5

Browse files
authored
fix bug when getting exp profile using api.runs() (#1511)
* fix bug when getting exp profile using api.runs() * accept gemini suggestion
1 parent f74040b commit e5e12e5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

swanlab/api/experiment/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from swanlab.api.user import User
1111
from swanlab.api.utils import Label, get_properties
12-
from swanlab.core_python.api.experiment import delete_experiment
12+
from swanlab.core_python.api.experiment import delete_experiment, get_single_experiment
1313
from swanlab.core_python.api.type import RunType
1414
from swanlab.core_python.client import Client
1515
from swanlab.error import ApiError
@@ -116,6 +116,9 @@ def profile(self) -> Profile:
116116
"""
117117
Experiment profile containing config, metadata, requirements, and conda.
118118
"""
119+
if 'profile' not in self._data:
120+
self._data = get_single_experiment(self._client, path=self.path)
121+
119122
return Profile(self._data.get('profile', {}))
120123

121124
@property
@@ -229,11 +232,11 @@ def metrics(self, keys: List[str] = None, x_axis: str = None, sample: int = None
229232

230233
# Strip "_step" suffix from column names (Python 3.8 compatible)
231234
def strip_suffix(col, suffix="_step"):
232-
return col[:-len(suffix)] if col.endswith(suffix) else col
235+
return col[: -len(suffix)] if col.endswith(suffix) else col
233236

234237
# Apply prefix removal and suffix stripping
235238
df.columns = [
236-
strip_suffix(col[len(prefix):]) if prefix and col.startswith(prefix) else strip_suffix(col)
239+
strip_suffix(col[len(prefix) :]) if prefix and col.startswith(prefix) else strip_suffix(col)
237240
for col in df.columns
238241
]
239242
dfs.append(df)
@@ -244,7 +247,9 @@ def strip_suffix(col, suffix="_step"):
244247

245248
# Handle x_axis: drop timestamp columns, reorder, filter nulls
246249
if use_x_axis:
247-
result_df = result_df.drop(columns=[c for c in result_df.columns if c.endswith("_timestamp")], errors='ignore')
250+
result_df = result_df.drop(
251+
columns=[c for c in result_df.columns if c.endswith("_timestamp")], errors='ignore'
252+
)
248253
if x_axis not in result_df.columns:
249254
raise ValueError(f"x_axis '{x_axis}' not found in result DataFrame")
250255
cols = [x_axis] + [c for c in result_df.columns if c != x_axis]
@@ -255,7 +260,7 @@ def strip_suffix(col, suffix="_step"):
255260
result_df = result_df.head(sample)
256261

257262
return result_df
258-
263+
259264
def delete(self):
260265
"""
261266
Delete this experiment.

0 commit comments

Comments
 (0)