Code Sample

import numpy as np
import pandas as pd
index = np.linspace(-3, 5, 7)
df = pd.DataFrame({'A': np.sin(index), 'B': np.cos(index**2)}, index=index)
type(df.apply(np.sum, axis=1, reduce=False))

Problem description

The docs say "If reduce is True a Series will always be returned, and if False a DataFrame will always be returned".

The type returned is a pandas.core.series.Series even though I set reduce=False

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.2.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None pandas: 0.20.3 pytest: 3.2.1 pip: 9.0.1 setuptools: 36.5.0.post20170921 Cython: 0.26.1 numpy: 1.13.1 scipy: 0.19.1 xarray: None IPython: 6.1.0 sphinx: 1.6.3 patsy: 0.4.1 dateutil: 2.6.1 pytz: 2017.2 blosc: None bottleneck: 1.2.1 tables: 3.4.2 numexpr: 2.6.2 feather: None matplotlib: 2.0.2 openpyxl: 2.4.8 xlrd: 1.1.0 xlwt: 1.3.0 xlsxwriter: 0.9.8 lxml: 3.8.0 bs4: 4.6.0 html5lib: 0.999999999 sqlalchemy: 1.1.13 pymysql: None psycopg2: None jinja2: 2.9.6 s3fs: None pandas_gbq: None pandas_datareader: None

Comment From: apopescu

Actually the docs are saying If the DataFrame is empty, apply will use reduce to determine whether the result should be a Series or a DataFrame. So i think what are you saying is true, but only for empties Dataframes.

Code sample:

df = pd.DataFrame()
type(df.apply(np.sum, axis=1, reduce=False))
pandas.core.frame.DataFrame
type(df.apply(np.sum, axis=1, reduce=True))
pandas.core.series.Series

Comment From: jreback

yeah the reduce arg is a bit of a red-herring. will be changing this after #18577, and incorporating this to result_type I think.

However this usage is functioning according to the docs.

thanks @apopescu