forked from scikit-learn-contrib/MAPIE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yonatan CARRANZA
committed
Apr 18, 2024
1 parent
1bc0cfb
commit f9580c7
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Union | ||
import numpy as np | ||
import pandas as pd | ||
from mapie._typing import NDArray | ||
|
||
|
||
class wrap_ndarray_and_dataframe: | ||
|
||
def __init__(self, X_array: Union[NDArray | pd.DataFrame]): | ||
""" | ||
This class is a wrapper for numpy arrays and pandas DataFrames. | ||
It is used to handle the indexing access to the data in a consistent way. | ||
:param X_array: | ||
""" | ||
self.X_array = X_array | ||
if isinstance(X_array, pd.DataFrame): | ||
self.X_array = pd.DataFrame(X_array, columns=X_array.columns) | ||
self.X_array = self.X_array.astype(self.X_array.dtypes.to_dict()) | ||
|
||
def __getitem__(self, item): | ||
if isinstance(self.X_array, pd.DataFrame): | ||
return self.X_array.iloc[item].values | ||
elif isinstance(self.X_array, np.ndarray): | ||
return self.X_array[item] | ||
else: | ||
raise ValueError("Input must be a numpy array or pandas DataFrame") |