You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/faq.rst
+148
Original file line number
Diff line number
Diff line change
@@ -369,3 +369,151 @@ just a thin layer around the ``QTableView``.
369
369
mw = MainWidget()
370
370
mw.show()
371
371
app.exec_()
372
+
373
+
374
+
375
+
.. _ref-subclassing-pandas:
376
+
377
+
Subclassing pandas Data Structures
378
+
----------------------------------
379
+
380
+
This section describes how to subclass ``pandas`` data structures to meet more specific needs. There are 2 points to be cared:
381
+
382
+
1. Override constructor properties.
383
+
2. Define original properties
384
+
385
+
.. note:: You can find actual example in `geopandas <https://github.com/geopandas/geopandas>`_ project.
386
+
387
+
Override Constructor Properties
388
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
389
+
390
+
Each data structures have constructor properties to specifying data constructors. By overriding these properties, you can retain defined-classes through ``pandas`` data manipulations.
391
+
392
+
There are 3 constructors to be defined:
393
+
394
+
- ``_constructor``: Used when a manipulation result has the same dimensionalities as the original.
395
+
- ``_constructor_sliced``: Used when a manipulation result has the lower dimensionalities as the original, such as ``DataFrame`` single columns slicing.
396
+
- ``_constructor_expanddim``: Used when a manipulation result has the higher dimensionalities as the original, such as ``Series.to_frame()`` and ``DataFrame.to_panel()``.
397
+
398
+
Following table shows how ``pandas`` data structures define constructor properties by default.
To let original data structures have additional properties, you should let ``pandas`` knows what properties are added. It is because ``pandas`` maps unknown properties to data names overriding ``__getattribute__``. Defining original properties can be done either ways:
474
+
475
+
1. Define ``_internal_names`` and ``_internal_names_set`` for temporary properties which WILL NOT be passed to manipulation results.
476
+
2. Define ``_metadata`` for normal properties which will be passed to manipulation results.
477
+
478
+
Below is an example to define 2 original properties, "internal_cache" as a temporary property and "added_property" as a normal property
0 commit comments