Skip to content

Commit

Permalink
Fixes for low versions of pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-hse-repository committed Mar 29, 2023
1 parent 5415a78 commit 8e169ef
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions etna/datasets/tsdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,8 @@ def get_level_dataset(self, target_level: str) -> "TSDataset":
target_level_df = self.to_pandas(features=target_names)

target_components_df = target_level_df.loc[:, pd.IndexSlice[:, self.target_components_names]]
target_level_df = target_level_df.drop(columns=list(self.target_components_names), level="feature")
if len(self.target_components_names) > 0: # for pandas >=1.1, <1.2
target_level_df = target_level_df.drop(columns=list(self.target_components_names), level="feature")

ts = TSDataset(
df=target_level_df,
Expand Down Expand Up @@ -1202,8 +1203,9 @@ def get_target_components(self) -> Optional[pd.DataFrame]:

def drop_target_components(self):
"""Drop target components from dataset."""
self.df.drop(columns=list(self.target_components_names), level="feature", inplace=True)
self._target_components_names = ()
if len(self.target_components_names) > 0: # for pandas >=1.1, <1.2
self.df.drop(columns=list(self.target_components_names), level="feature", inplace=True)
self._target_components_names = ()

@property
def columns(self) -> pd.core.indexes.multi.MultiIndex:
Expand Down

0 comments on commit 8e169ef

Please sign in to comment.