@@ -140,25 +140,44 @@ API changes
140
140
applied would be called with an empty ``Series`` to guess whether a
141
141
``Series`` or ``DataFrame`` should be returned:
142
142
143
- .. ipython:: python
143
+ .. code-block:: ipython
144
+
145
+ In [32]: def applied_func(col):
146
+ ....: print("Apply function being called with: ", col)
147
+ ....: return col.sum()
148
+ ....:
144
149
145
- def applied_func(col):
146
- print("Apply function being called with: ", col)
147
- return col.sum()
150
+ In [33]: empty = DataFrame(columns=['a', 'b'])
148
151
149
- empty = DataFrame(columns=['a', 'b'])
150
- empty.apply(applied_func)
152
+ In [34]: empty.apply(applied_func)
153
+ Apply function being called with: Series([], Length: 0, dtype: float64)
154
+ Out[34]:
155
+ a NaN
156
+ b NaN
157
+ Length: 2, dtype: float64
151
158
152
159
Now, when ``apply`` is called on an empty ``DataFrame``: if the ``reduce``
153
160
argument is ``True`` a ``Series`` will returned, if it is ``False`` a
154
161
``DataFrame`` will be returned, and if it is ``None`` (the default) the
155
162
function being applied will be called with an empty series to try and guess
156
163
the return type.
157
164
158
- .. ipython:: python
165
+ .. code-block:: ipython
166
+
167
+ In [35]: empty.apply(applied_func, reduce=True)
168
+ Out[35]:
169
+ a NaN
170
+ b NaN
171
+ Length: 2, dtype: float64
172
+
173
+ In [36]: empty.apply(applied_func, reduce=False)
174
+ Out[36]:
175
+ Empty DataFrame
176
+ Columns: [a, b]
177
+ Index: []
178
+
179
+ [0 rows x 2 columns]
159
180
160
- empty.apply(applied_func, reduce=True)
161
- empty.apply(applied_func, reduce=False)
162
181
163
182
Prior Version Deprecations/Changes
164
183
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments