Skip to content

Commit

Permalink
Treat multiindex column names with all but first empty components as …
Browse files Browse the repository at this point in the history
…strings
  • Loading branch information
druzsan committed Feb 14, 2024
1 parent bb7d770 commit 8511f78
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions renumics/spotlight_plugins/core/pandas_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ def __init__(self, source: Union[Path, pd.DataFrame]):
def column_names(self) -> List[str]:
column_names: List[str] = []
for column in self._df.columns:
column_name = str(column)
if (
isinstance(column, tuple)
and len(column)
and all(name == "" for name in column[1:])
):
column_name = str(column[0])
else:
column_name = str(column)
if column_name not in column_names:
column_names.append(column_name)
continue
Expand Down Expand Up @@ -139,7 +146,7 @@ def get_column_values(
column_name: str,
indices: Union[List[int], np.ndarray, slice] = slice(None),
) -> np.ndarray:
column = self._get_column(column_name).iloc[indices] # type: ignore
column = cast(pd.Series, self._get_column(column_name).iloc[indices]) # type: ignore
if pd.api.types.is_bool_dtype(column):
values = column.to_numpy(na_value=pd.NA) # type: ignore
na_mask = column.isna()
Expand Down

0 comments on commit 8511f78

Please sign in to comment.