-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Fixed examples in pandas/core/groupby/
#33230
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
DOC: Fixed examples in pandas/core/groupby/
#33230
Conversation
pandas/core/groupby/
pandas/core/groupby/
@@ -2005,7 +2005,7 @@ def cumcount(self, ascending: bool = True): | |||
|
|||
Essentially this is equivalent to | |||
|
|||
>>> self.apply(lambda x: pd.Series(np.arange(len(x)), x.index)) | |||
self.apply(lambda x: pd.Series(np.arange(len(x)), x.index)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still render as code when you build the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is keeping this as it was not an option? I don’t think we add code-blocks to docstring normally since they are oriented more towards generated HTML / PDF output and aren’t super useful in say a shell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only solution that comes to my mind is to add # doctest: +SKIP
to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback do you know how we typically handle these? I don't think we use code-block in docstrings do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WillAyd We actually do: (although I'm not sure if this is wanted)
pandas/pandas/core/accessor.py
Lines 223 to 266 in cabc31a
.. code-block:: python | |
def __init__(self, pandas_object): # noqa: E999 | |
... | |
For consistency with pandas methods, you should raise an ``AttributeError`` | |
if the data passed to your accessor has an incorrect dtype. | |
>>> pd.Series(['a', 'b']).dt | |
Traceback (most recent call last): | |
... | |
AttributeError: Can only use .dt accessor with datetimelike values | |
Examples | |
-------- | |
In your library code:: | |
import pandas as pd | |
@pd.api.extensions.register_dataframe_accessor("geo") | |
class GeoAccessor: | |
def __init__(self, pandas_obj): | |
self._obj = pandas_obj | |
@property | |
def center(self): | |
# return the geographic center point of this DataFrame | |
lat = self._obj.latitude | |
lon = self._obj.longitude | |
return (float(lon.mean()), float(lat.mean())) | |
def plot(self): | |
# plot this array's data on a map, e.g., using Cartopy | |
pass | |
Back in an interactive IPython session: | |
.. code-block:: ipython | |
In [1]: ds = pd.DataFrame({{"longitude": np.linspace(0, 10), | |
...: "latitude": np.linspace(0, 20)}}) | |
In [2]: ds.geo.center | |
Out[2]: (5.0, 10.0) | |
In [3]: ds.geo.plot() # plots data on a map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be using triple backticks? Otherwise, a skip seems reasonable. Or may be @jorisvandenbossche has a better idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks @MomIsBestFriend
Thanks @MomIsBestFriend |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff