Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions skore/src/skore/_sklearn/_estimator/data_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def _retrieve_data_as_frame(
raise ValueError(err_msg.format(f"X_{dataset}", data_source))
elif not sbd.is_dataframe(X):
X = pd.DataFrame(X, columns=[f"Feature {i}" for i in range(X.shape[1])])
else:
if not all(isinstance(col, str) for col in X.columns):
X = X.copy()
X.columns = [str(col) for col in X.columns]

if with_y:
if y is None:
Expand All @@ -63,6 +67,13 @@ def _retrieve_data_as_frame(
else:
columns = [f"Target {i}" for i in range(y.shape[1])]
y = pd.DataFrame(y, columns=columns)
else:
if not all(isinstance(col, str) for col in y.columns):
y = y.copy()
if y.shape[1] == 1 and list(y.columns) == [0]:
y.columns = ["Target"]
else:
y.columns = [str(col) for col in y.columns]

return X, y

Expand Down
3 changes: 3 additions & 0 deletions skore/tests/unit/displays/table_report/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def test_constructor(display):
pd.DataFrame(
np.ones((100, 5)), columns=[f"Feature number {i}" for i in range(5)]
),
pd.DataFrame(np.ones((100, 5))),
pd.DataFrame(np.ones((100, 5)), columns=["a", 1, "c", 3, "e"]),
],
)
@pytest.mark.parametrize(
Expand All @@ -78,6 +80,7 @@ def test_constructor(display):
np.ones(100),
pd.Series(np.ones(100)),
pd.DataFrame(np.ones((100, 1)), columns=["Target"]),
pd.DataFrame(np.ones((100, 1))),
],
)
def test_X_y(X, y):
Expand Down
Loading