Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.__version__
df = pd.DataFrame(data={'x': [1, 2, 3, 4, 5],
'y': [2, 4, 6, 8, 10]},
dtype=int)
? df.astype
Issue Description
In JupyterLab and in Spyder the docstrings of DataFrame instances do not show when for example when inputting the following alongside shift and tab:
df.astype()
Attempting to look up the docstring gives a ValueError:
? df.astype
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Expected Behavior
A comparison of the same code ran in pandas 2.0.0 with pandas 1.5.3:
Installed Versions
Comment From: phofl
Hi, thanks for your report. Can you show the full traceback please?
Comment From: PhilipYip1988
Here is the full error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[4], line 1
----> 1 get_ipython().run_line_magic('pinfo', ' df.astype')
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\IPython\core\interactiveshell.py:2414, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2412 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2413 with self.builtin_trap:
-> 2414 result = fn(*args, **kwargs)
2416 # The code below prevents the output from being displayed
2417 # when using magics with decodator @output_can_be_silenced
2418 # when the last Python token in the expression is a ';'.
2419 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\IPython\core\magics\namespace.py:58, in NamespaceMagics.pinfo(self, parameter_s, namespaces)
56 self.psearch(oname)
57 else:
---> 58 self.shell._inspect('pinfo', oname, detail_level=detail_level,
59 namespaces=namespaces)
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\IPython\core\interactiveshell.py:1795, in InteractiveShell._inspect(self, meth, oname, namespaces, **kw)
1793 pmethod(info.obj, oname, formatter)
1794 elif meth == 'pinfo':
-> 1795 pmethod(
1796 info.obj,
1797 oname,
1798 formatter,
1799 info,
1800 enable_html_pager=self.enable_html_pager,
1801 **kw,
1802 )
1803 else:
1804 pmethod(info.obj, oname)
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\IPython\core\oinspect.py:782, in Inspector.pinfo(self, obj, oname, formatter, info, detail_level, enable_html_pager, omit_sections)
758 """Show detailed information about an object.
759
760 Optional arguments:
(...)
779 - omit_sections: set of section keys and titles to omit
780 """
781 assert info is not None
--> 782 info_b: Bundle = self._get_info(
783 obj, oname, formatter, info, detail_level, omit_sections=omit_sections
784 )
785 if not enable_html_pager:
786 del info_b["text/html"]
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\IPython\core\oinspect.py:738, in Inspector._get_info(self, obj, oname, formatter, info, detail_level, omit_sections)
712 def _get_info(
713 self,
714 obj: Any,
(...)
719 omit_sections=(),
720 ) -> Bundle:
721 """Retrieve an info dict and format it.
722
723 Parameters
(...)
735 Titles or keys to omit from output (can be set, tuple, etc., anything supporting `in`)
736 """
--> 738 info_dict = self.info(obj, oname=oname, info=info, detail_level=detail_level)
739 bundle = self._make_info_unformatted(
740 obj,
741 info_dict,
(...)
744 omit_sections=omit_sections,
745 )
746 return self.format_mime(bundle)
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\IPython\core\oinspect.py:838, in Inspector.info(self, obj, oname, info, detail_level)
836 parents_docs = None
837 prelude = ""
--> 838 if info and info.parent and hasattr(info.parent, HOOK_NAME):
839 parents_docs_dict = getattr(info.parent, HOOK_NAME)
840 parents_docs = parents_docs_dict.get(att_name, None)
File ~\mambaforge\envs\jupyterlab\Lib\site-packages\pandas\core\generic.py:1466, in NDFrame.__nonzero__(self)
1464 @final
1465 def __nonzero__(self) -> NoReturn:
-> 1466 raise ValueError(
1467 f"The truth value of a {type(self).__name__} is ambiguous. "
1468 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1469 )
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Comment From: asishm-wk
This likely changed with an IPython release. This reproduces in 1.5.3 as well as well as with 0.25.3
From the traceback --> 838 if info and info.parent and hasattr(info.parent, HOOK_NAME)
the if info
part would raise the ValueError since bool(pd.DataFrame)
has always raised. (without stepping in to a debugger I'm assuming the info
object is the dataframe)
Comment From: asishm-wk
On my personal device which has an old pandas dev-env with IPython 8.7.0, this doesn't reproduce
Comment From: igumnov-daniel
same:
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
File "C:\Users\igumn\miniconda3\envs\hock\Lib\site-packages\ipykernel\kernelbase.py", line 409, in dispatch_shell
await result
File "C:\Users\igumn\miniconda3\envs\hock\Lib\site-packages\ipykernel\kernelbase.py", line 798, in inspect_request
reply_content = self.do_inspect(
^^^^^^^^^^^^^^^^
File "C:\Users\igumn\miniconda3\envs\hock\Lib\site-packages\ipykernel\ipkernel.py", line 555, in do_inspect
bundle = self.shell.object_inspect_mime(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\igumn\miniconda3\envs\hock\Lib\site-packages\IPython\core\interactiveshell.py", line 1838, in object_inspect_mime
return self.inspector._get_info(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\igumn\miniconda3\envs\hock\Lib\site-packages\IPython\core\oinspect.py", line 738, in _get_info
info_dict = self.info(obj, oname=oname, info=info, detail_level=detail_level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\igumn\miniconda3\envs\hock\Lib\site-packages\IPython\core\oinspect.py", line 838, in info
if info and info.parent and hasattr(info.parent, HOOK_NAME):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Comment From: phofl
Looks like an upstream issue then
Comment From: PhilipYip1988
Just to confirm, downgrading IPython from 8.12.0 to 8.11.0 restored the code completion on my system.
Comment From: phofl
Closing then. Please report this upstream
Comment From: PhilipYip1988
This is fixed with IPython 8.13.1.