Skip to content

Commit 8744d36

Browse files
authored
DOC: update code style for development doc and user guide #36777 (#36821)
1 parent d5cddbd commit 8744d36

File tree

4 files changed

+409
-370
lines changed

4 files changed

+409
-370
lines changed

doc/source/development/extending.rst

+14-14
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ decorate a class, providing the name of attribute to add. The class's
3434
@staticmethod
3535
def _validate(obj):
3636
# verify there is a column latitude and a column longitude
37-
if 'latitude' not in obj.columns or 'longitude' not in obj.columns:
37+
if "latitude" not in obj.columns or "longitude" not in obj.columns:
3838
raise AttributeError("Must have 'latitude' and 'longitude'.")
3939
4040
@property
@@ -176,6 +176,7 @@ your ``MyExtensionArray`` class, as follows:
176176
177177
from pandas.api.extensions import ExtensionArray, ExtensionScalarOpsMixin
178178
179+
179180
class MyExtensionArray(ExtensionArray, ExtensionScalarOpsMixin):
180181
pass
181182
@@ -271,6 +272,7 @@ included as a column in a pandas DataFrame):
271272
def __arrow_array__(self, type=None):
272273
# convert the underlying array values to a pyarrow Array
273274
import pyarrow
275+
274276
return pyarrow.array(..., type=type)
275277
276278
The ``ExtensionDtype.__from_arrow__`` method then controls the conversion
@@ -347,7 +349,6 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
347349
.. code-block:: python
348350
349351
class SubclassedSeries(pd.Series):
350-
351352
@property
352353
def _constructor(self):
353354
return SubclassedSeries
@@ -358,7 +359,6 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
358359
359360
360361
class SubclassedDataFrame(pd.DataFrame):
361-
362362
@property
363363
def _constructor(self):
364364
return SubclassedDataFrame
@@ -377,7 +377,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
377377
>>> type(to_framed)
378378
<class '__main__.SubclassedDataFrame'>
379379
380-
>>> df = SubclassedDataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
380+
>>> df = SubclassedDataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
381381
>>> df
382382
A B C
383383
0 1 4 7
@@ -387,7 +387,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
387387
>>> type(df)
388388
<class '__main__.SubclassedDataFrame'>
389389
390-
>>> sliced1 = df[['A', 'B']]
390+
>>> sliced1 = df[["A", "B"]]
391391
>>> sliced1
392392
A B
393393
0 1 4
@@ -397,7 +397,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
397397
>>> type(sliced1)
398398
<class '__main__.SubclassedDataFrame'>
399399
400-
>>> sliced2 = df['A']
400+
>>> sliced2 = df["A"]
401401
>>> sliced2
402402
0 1
403403
1 2
@@ -422,39 +422,39 @@ Below is an example to define two original properties, "internal_cache" as a tem
422422
class SubclassedDataFrame2(pd.DataFrame):
423423
424424
# temporary properties
425-
_internal_names = pd.DataFrame._internal_names + ['internal_cache']
425+
_internal_names = pd.DataFrame._internal_names + ["internal_cache"]
426426
_internal_names_set = set(_internal_names)
427427
428428
# normal properties
429-
_metadata = ['added_property']
429+
_metadata = ["added_property"]
430430
431431
@property
432432
def _constructor(self):
433433
return SubclassedDataFrame2
434434
435435
.. code-block:: python
436436
437-
>>> df = SubclassedDataFrame2({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
437+
>>> df = SubclassedDataFrame2({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
438438
>>> df
439439
A B C
440440
0 1 4 7
441441
1 2 5 8
442442
2 3 6 9
443443
444-
>>> df.internal_cache = 'cached'
445-
>>> df.added_property = 'property'
444+
>>> df.internal_cache = "cached"
445+
>>> df.added_property = "property"
446446
447447
>>> df.internal_cache
448448
cached
449449
>>> df.added_property
450450
property
451451
452452
# properties defined in _internal_names is reset after manipulation
453-
>>> df[['A', 'B']].internal_cache
453+
>>> df[["A", "B"]].internal_cache
454454
AttributeError: 'SubclassedDataFrame2' object has no attribute 'internal_cache'
455455
456456
# properties defined in _metadata are retained
457-
>>> df[['A', 'B']].added_property
457+
>>> df[["A", "B"]].added_property
458458
property
459459
460460
.. _extending.plotting-backends:
@@ -468,7 +468,7 @@ one based on Matplotlib. For example:
468468

469469
.. code-block:: python
470470
471-
>>> pd.set_option('plotting.backend', 'backend.module')
471+
>>> pd.set_option("plotting.backend", "backend.module")
472472
>>> pd.Series([1, 2, 3]).plot()
473473
474474
This would be more or less equivalent to:

0 commit comments

Comments
 (0)