Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Series' object has no attribute 'iteritems' - iteritems seems to have been deprecated #704

Open
wayner9 opened this issue Nov 2, 2023 · 4 comments

Comments

@wayner9
Copy link

wayner9 commented Nov 2, 2023

Problem Description

Get an error when trying to generate Tearsheet. 'Series' object has no attribute 'iteritems'

Apparently Pandas 2.0 deprecated iteritems. I am using pandas 2.1.2.

Will this be fixed?

@qq17908
Copy link

qq17908 commented Nov 4, 2023

edit the plotting.py file in ur site packages folder from iteritems() to items()

@Hongshen-Yang
Copy link

Hongshen-Yang commented Nov 22, 2023

edit the plotting.py file in ur site packages folder from iteritems() to items()

Then it's ValueError: Incompatible indexer with Series...

File [c:\Users\hyan212\Miniconda3\lib\site-packages\pyfolio\plotting.py:1664](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1664), in show_worst_drawdown_periods(returns, top)
   [1648](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1648) def show_worst_drawdown_periods(returns, top=5):
   [1649](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1649)     """
   [1650](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1650)     Prints information about the worst drawdown periods.
   [1651](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1651) 
   (...)
   [1661](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1661)         Amount of top drawdowns periods to plot (default 5).
   [1662](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1662)     """
-> [1664](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1664)     drawdown_df = timeseries.gen_drawdown_table(returns, top=top)
   [1665](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1665)     utils.print_table(
   [1666](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1666)         drawdown_df.sort_values('Net drawdown in %', ascending=False),
   [1667](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1667)         name='Worst drawdown periods',
   [1668](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1668)         float_format='{0:.2f}'.format,
   [1669](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/plotting.py:1669)     )

File [c:\Users\hyan212\Miniconda3\lib\site-packages\pyfolio\timeseries.py:1015](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1015), in gen_drawdown_table(returns, top)
   [1012](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1012)     else:
   [1013](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1013)         df_drawdowns.loc[i, 'Recovery date'] = (recovery.to_pydatetime()
   [1014](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1014)                                                 .strftime('%Y-%m-%d'))
-> [1015](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1015)     df_drawdowns.loc[i, 'Net drawdown in %'] = (
   [1016](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1016)         (df_cum.loc[peak] - df_cum.loc[valley]) / df_cum.loc[peak]) * 100
   [1018](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1018) df_drawdowns['Peak date'] = pd.to_datetime(df_drawdowns['Peak date'])
   [1019](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pyfolio/timeseries.py:1019) df_drawdowns['Valley date'] = pd.to_datetime(df_drawdowns['Valley date'])

File [c:\Users\hyan212\Miniconda3\lib\site-packages\pandas\core\indexing.py:885](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:885), in _LocationIndexer.__setitem__(self, key, value)
    [882](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:882) self._has_valid_setitem_indexer(key)
    [884](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:884) iloc = self if self.name == "iloc" else self.obj.iloc
--> [885](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:885) iloc._setitem_with_indexer(indexer, value, self.name)

File [c:\Users\hyan212\Miniconda3\lib\site-packages\pandas\core\indexing.py:1895](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:1895), in _iLocIndexer._setitem_with_indexer(self, indexer, value, name)
   [1893](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:1893)     self._setitem_with_indexer_split_path(indexer, value, name)
   [1894](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:1894) else:
-> [1895](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:1895)     self._setitem_single_block(indexer, value, name)

File [c:\Users\hyan212\Miniconda3\lib\site-packages\pandas\core\indexing.py:2129](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2129), in _iLocIndexer._setitem_single_block(self, indexer, value, name)
   [2123](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2123)     indexer = maybe_convert_ix(*indexer)  # e.g. test_setitem_frame_align
   [2125](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2125) if (isinstance(value, ABCSeries) and name != "iloc") or isinstance(value, dict):
   [2126](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2126)     # TODO(EA): ExtensionBlock.setitem this causes issues with
   [2127](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2127)     # setting for extensionarrays that store dicts. Need to decide
   [2128](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2128)     # if it's worth supporting that.
-> [2129](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2129)     value = self._align_series(indexer, Series(value))
   [2131](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2131) elif isinstance(value, ABCDataFrame) and name != "iloc":
   [2132](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2132)     value = self._align_frame(indexer, value)._values

File [c:\Users\hyan212\Miniconda3\lib\site-packages\pandas\core\indexing.py:2368](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2368), in _iLocIndexer._align_series(self, indexer, ser, multiindex_indexer, using_cow)
   [2364](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2364)         return ser._values.copy()
   [2366](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2366)     return ser.reindex(ax)._values
-> [2368](file:///C:/Users/hyan212/Miniconda3/lib/site-packages/pandas/core/indexing.py:2368) raise ValueError("Incompatible indexer with Series")

ValueError: Incompatible indexer with Series

@sandroboehme
Copy link

I was just about to open a bug entry here as I haven't got a response to my Stackoverflow question yet.
With Pandas <2.0.0 I haven't got it running either but I'd certainly prefer a more recent version.

More details to reproduce it can be found here if needed:
https://stackoverflow.com/questions/77636192/attributeerror-series-object-has-no-attribute-iteritems-in-simple-custom
But Pandas 2.0 deprecated iteritems is kinda enough of a description I guess :-D

@sandroboehme
Copy link

It looks like Pyfolio is not maintained anymore.
I've got it working by using
pyfolio-reloaded. See:
#690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants