Skip to content

DOC: update code style for development doc and user guide #36777 #36821

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

Merged
merged 4 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions doc/source/development/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ decorate a class, providing the name of attribute to add. The class's
@staticmethod
def _validate(obj):
# verify there is a column latitude and a column longitude
if 'latitude' not in obj.columns or 'longitude' not in obj.columns:
if "latitude" not in obj.columns or "longitude" not in obj.columns:
raise AttributeError("Must have 'latitude' and 'longitude'.")

@property
Expand Down Expand Up @@ -176,6 +176,7 @@ your ``MyExtensionArray`` class, as follows:

from pandas.api.extensions import ExtensionArray, ExtensionScalarOpsMixin


class MyExtensionArray(ExtensionArray, ExtensionScalarOpsMixin):
pass

Expand Down Expand Up @@ -271,6 +272,7 @@ included as a column in a pandas DataFrame):
def __arrow_array__(self, type=None):
# convert the underlying array values to a pyarrow Array
import pyarrow

return pyarrow.array(..., type=type)

The ``ExtensionDtype.__from_arrow__`` method then controls the conversion
Expand Down Expand Up @@ -347,7 +349,6 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
.. code-block:: python

class SubclassedSeries(pd.Series):

@property
def _constructor(self):
return SubclassedSeries
Expand All @@ -358,7 +359,6 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame


class SubclassedDataFrame(pd.DataFrame):

@property
def _constructor(self):
return SubclassedDataFrame
Expand All @@ -377,7 +377,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
>>> type(to_framed)
<class '__main__.SubclassedDataFrame'>

>>> df = SubclassedDataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
>>> df = SubclassedDataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
>>> df
A B C
0 1 4 7
Expand All @@ -387,7 +387,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
>>> type(df)
<class '__main__.SubclassedDataFrame'>

>>> sliced1 = df[['A', 'B']]
>>> sliced1 = df[["A", "B"]]
>>> sliced1
A B
0 1 4
Expand All @@ -397,7 +397,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
>>> type(sliced1)
<class '__main__.SubclassedDataFrame'>

>>> sliced2 = df['A']
>>> sliced2 = df["A"]
>>> sliced2
0 1
1 2
Expand All @@ -422,39 +422,39 @@ Below is an example to define two original properties, "internal_cache" as a tem
class SubclassedDataFrame2(pd.DataFrame):

# temporary properties
_internal_names = pd.DataFrame._internal_names + ['internal_cache']
_internal_names = pd.DataFrame._internal_names + ["internal_cache"]
_internal_names_set = set(_internal_names)

# normal properties
_metadata = ['added_property']
_metadata = ["added_property"]

@property
def _constructor(self):
return SubclassedDataFrame2

.. code-block:: python

>>> df = SubclassedDataFrame2({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
>>> df = SubclassedDataFrame2({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
>>> df
A B C
0 1 4 7
1 2 5 8
2 3 6 9

>>> df.internal_cache = 'cached'
>>> df.added_property = 'property'
>>> df.internal_cache = "cached"
>>> df.added_property = "property"

>>> df.internal_cache
cached
>>> df.added_property
property

# properties defined in _internal_names is reset after manipulation
>>> df[['A', 'B']].internal_cache
>>> df[["A", "B"]].internal_cache
AttributeError: 'SubclassedDataFrame2' object has no attribute 'internal_cache'

# properties defined in _metadata are retained
>>> df[['A', 'B']].added_property
>>> df[["A", "B"]].added_property
property

.. _extending.plotting-backends:
Expand All @@ -468,7 +468,7 @@ one based on Matplotlib. For example:

.. code-block:: python

>>> pd.set_option('plotting.backend', 'backend.module')
>>> pd.set_option("plotting.backend", "backend.module")
>>> pd.Series([1, 2, 3]).plot()

This would be more or less equivalent to:
Expand Down
Loading