@@ -34,7 +34,7 @@ decorate a class, providing the name of attribute to add. The class's
34
34
@ staticmethod
35
35
def _validate (obj ):
36
36
# 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:
38
38
raise AttributeError (" Must have 'latitude' and 'longitude'." )
39
39
40
40
@ property
@@ -176,6 +176,7 @@ your ``MyExtensionArray`` class, as follows:
176
176
177
177
from pandas.api.extensions import ExtensionArray, ExtensionScalarOpsMixin
178
178
179
+
179
180
class MyExtensionArray (ExtensionArray , ExtensionScalarOpsMixin ):
180
181
pass
181
182
@@ -271,6 +272,7 @@ included as a column in a pandas DataFrame):
271
272
def __arrow_array__ (self , type = None ):
272
273
# convert the underlying array values to a pyarrow Array
273
274
import pyarrow
275
+
274
276
return pyarrow.array(... , type = type )
275
277
276
278
The ``ExtensionDtype.__from_arrow__ `` method then controls the conversion
@@ -347,7 +349,6 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
347
349
.. code-block :: python
348
350
349
351
class SubclassedSeries (pd .Series ):
350
-
351
352
@ property
352
353
def _constructor (self ):
353
354
return SubclassedSeries
@@ -358,7 +359,6 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
358
359
359
360
360
361
class SubclassedDataFrame (pd .DataFrame ):
361
-
362
362
@ property
363
363
def _constructor (self ):
364
364
return SubclassedDataFrame
@@ -377,7 +377,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
377
377
>> > type (to_framed)
378
378
< class ' __main__.SubclassedDataFrame' >
379
379
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 ]})
381
381
>> > df
382
382
A B C
383
383
0 1 4 7
@@ -387,7 +387,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
387
387
>> > type (df)
388
388
< class ' __main__.SubclassedDataFrame' >
389
389
390
- >> > sliced1 = df[[' A ' , ' B ' ]]
390
+ >> > sliced1 = df[[" A " , " B " ]]
391
391
>> > sliced1
392
392
A B
393
393
0 1 4
@@ -397,7 +397,7 @@ Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame
397
397
>> > type (sliced1)
398
398
< class ' __main__.SubclassedDataFrame' >
399
399
400
- >> > sliced2 = df[' A ' ]
400
+ >> > sliced2 = df[" A " ]
401
401
>> > sliced2
402
402
0 1
403
403
1 2
@@ -422,39 +422,39 @@ Below is an example to define two original properties, "internal_cache" as a tem
422
422
class SubclassedDataFrame2 (pd .DataFrame ):
423
423
424
424
# temporary properties
425
- _internal_names = pd.DataFrame._internal_names + [' internal_cache' ]
425
+ _internal_names = pd.DataFrame._internal_names + [" internal_cache" ]
426
426
_internal_names_set = set (_internal_names)
427
427
428
428
# normal properties
429
- _metadata = [' added_property' ]
429
+ _metadata = [" added_property" ]
430
430
431
431
@ property
432
432
def _constructor (self ):
433
433
return SubclassedDataFrame2
434
434
435
435
.. code-block :: python
436
436
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 ]})
438
438
>> > df
439
439
A B C
440
440
0 1 4 7
441
441
1 2 5 8
442
442
2 3 6 9
443
443
444
- >> > df.internal_cache = ' cached'
445
- >> > df.added_property = ' property'
444
+ >> > df.internal_cache = " cached"
445
+ >> > df.added_property = " property"
446
446
447
447
>> > df.internal_cache
448
448
cached
449
449
>> > df.added_property
450
450
property
451
451
452
452
# properties defined in _internal_names is reset after manipulation
453
- >> > df[[' A ' , ' B ' ]].internal_cache
453
+ >> > df[[" A " , " B " ]].internal_cache
454
454
AttributeError : ' SubclassedDataFrame2' object has no attribute ' internal_cache'
455
455
456
456
# properties defined in _metadata are retained
457
- >> > df[[' A ' , ' B ' ]].added_property
457
+ >> > df[[" A " , " B " ]].added_property
458
458
property
459
459
460
460
.. _extending.plotting-backends :
@@ -468,7 +468,7 @@ one based on Matplotlib. For example:
468
468
469
469
.. code-block :: python
470
470
471
- >> > pd.set_option(' plotting.backend' , ' backend.module' )
471
+ >> > pd.set_option(" plotting.backend" , " backend.module" )
472
472
>> > pd.Series([1 , 2 , 3 ]).plot()
473
473
474
474
This would be more or less equivalent to:
0 commit comments