<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<p dir="auto">Executing</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd

df = pd.DataFrame({'a':[pd.Timestamp('2010-02-01'),
                        pd.Timestamp('2010-02-04'),
                        pd.Timestamp('2010-02-05'),
                        pd.Timestamp('2010-02-06')],
                   'b':[9,5,4,3], 'c':[5,3,4,2], 'd':[1,2,3,4]})

def fun(x):
    return (1,2)

df.apply(fun, axis=1)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'a'</span>:[<span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'2010-02-01'</span>),
                        <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'2010-02-04'</span>),
                        <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'2010-02-05'</span>),
                        <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'2010-02-06'</span>)],
                   <span class="pl-s">'b'</span>:[<span class="pl-c1">9</span>,<span class="pl-c1">5</span>,<span class="pl-c1">4</span>,<span class="pl-c1">3</span>], <span class="pl-s">'c'</span>:[<span class="pl-c1">5</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">2</span>], <span class="pl-s">'d'</span>:[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>]})

<span class="pl-k">def</span> <span class="pl-en">fun</span>(<span class="pl-s1">x</span>):
    <span class="pl-k">return</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-s1">df</span>.<span class="pl-en">apply</span>(<span class="pl-s1">fun</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)</pre></div>
<p dir="auto">raises an exception</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in create_block_manager_from_arrays(arrays, names, axes)
   4309         blocks = form_blocks(arrays, names, axes)
-&gt; 4310         mgr = BlockManager(blocks, axes)
   4311         mgr._consolidate_inplace()

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in __init__(self, blocks, axes, do_integrity_check, fastpath)
   2794         if do_integrity_check:
-&gt; 2795             self._verify_integrity()
   2796 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in _verify_integrity(self)
   3005             if block._verify_integrity and block.shape[1:] != mgr_shape[1:]:
-&gt; 3006                 construction_error(tot_items, block.shape[1:], self.axes)
   3007         if len(self.items) != tot_items:

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e)
   4279     raise ValueError(&quot;Shape of passed values is {0}, indices imply {1}&quot;.format(
-&gt; 4280         passed, implied))
   4281 

ValueError: Shape of passed values is (4, 2), indices imply (4, 4)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
&lt;ipython-input-26-7b305f7b3474&gt; in &lt;module&gt;()
      8     return (1,2)
      9 
---&gt; 10 df.apply(fun, axis=1)

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, broadcast, raw, reduce, args, **kwds)
   4260                         f, axis,
   4261                         reduce=reduce,
-&gt; 4262                         ignore_failures=ignore_failures)
   4263             else:
   4264                 return self._apply_broadcast(f, axis)

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _apply_standard(self, func, axis, ignore_failures, reduce)
   4373                 index = None
   4374 
-&gt; 4375             result = self._constructor(data=results, index=index)
   4376             result.columns = res_index
   4377 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    273                                  dtype=dtype, copy=copy)
    274         elif isinstance(data, dict):
--&gt; 275             mgr = self._init_dict(data, index, columns, dtype=dtype)
    276         elif isinstance(data, ma.MaskedArray):
    277             import numpy.ma.mrecords as mrecords

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _init_dict(self, data, index, columns, dtype)
    409             arrays = [data[k] for k in keys]
    410 
--&gt; 411         return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    412 
    413     def _init_ndarray(self, values, index, columns, dtype=None, copy=False):

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _arrays_to_mgr(arrays, arr_names, index, columns, dtype)
   5504     axes = [_ensure_index(columns), _ensure_index(index)]
   5505 
-&gt; 5506     return create_block_manager_from_arrays(arrays, arr_names, axes)
   5507 
   5508 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in create_block_manager_from_arrays(arrays, names, axes)
   4312         return mgr
   4313     except ValueError as e:
-&gt; 4314         construction_error(len(arrays), arrays[0].shape, axes, e)
   4315 
   4316 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e)
   4278         raise ValueError(&quot;Empty data passed with indices specified.&quot;)
   4279     raise ValueError(&quot;Shape of passed values is {0}, indices imply {1}&quot;.format(
-&gt; 4280         passed, implied))
   4281 
   4282 

ValueError: Shape of passed values is (4, 2), indices imply (4, 4)"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in create_block_manager_from_arrays(arrays, names, axes)
   4309         blocks = form_blocks(arrays, names, axes)
-&gt; 4310         mgr = BlockManager(blocks, axes)
   4311         mgr._consolidate_inplace()

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in __init__(self, blocks, axes, do_integrity_check, fastpath)
   2794         if do_integrity_check:
-&gt; 2795             self._verify_integrity()
   2796 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in _verify_integrity(self)
   3005             if block._verify_integrity and block.shape[1:] != mgr_shape[1:]:
-&gt; 3006                 construction_error(tot_items, block.shape[1:], self.axes)
   3007         if len(self.items) != tot_items:

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e)
   4279     raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-&gt; 4280         passed, implied))
   4281 

ValueError: Shape of passed values is (4, 2), indices imply (4, 4)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
&lt;ipython-input-26-7b305f7b3474&gt; in &lt;module&gt;()
      8     return (1,2)
      9 
---&gt; 10 df.apply(fun, axis=1)

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, broadcast, raw, reduce, args, **kwds)
   4260                         f, axis,
   4261                         reduce=reduce,
-&gt; 4262                         ignore_failures=ignore_failures)
   4263             else:
   4264                 return self._apply_broadcast(f, axis)

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _apply_standard(self, func, axis, ignore_failures, reduce)
   4373                 index = None
   4374 
-&gt; 4375             result = self._constructor(data=results, index=index)
   4376             result.columns = res_index
   4377 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    273                                  dtype=dtype, copy=copy)
    274         elif isinstance(data, dict):
--&gt; 275             mgr = self._init_dict(data, index, columns, dtype=dtype)
    276         elif isinstance(data, ma.MaskedArray):
    277             import numpy.ma.mrecords as mrecords

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _init_dict(self, data, index, columns, dtype)
    409             arrays = [data[k] for k in keys]
    410 
--&gt; 411         return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    412 
    413     def _init_ndarray(self, values, index, columns, dtype=None, copy=False):

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _arrays_to_mgr(arrays, arr_names, index, columns, dtype)
   5504     axes = [_ensure_index(columns), _ensure_index(index)]
   5505 
-&gt; 5506     return create_block_manager_from_arrays(arrays, arr_names, axes)
   5507 
   5508 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in create_block_manager_from_arrays(arrays, names, axes)
   4312         return mgr
   4313     except ValueError as e:
-&gt; 4314         construction_error(len(arrays), arrays[0].shape, axes, e)
   4315 
   4316 

/Users/wilmat01/anaconda/lib/python3.6/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e)
   4278         raise ValueError("Empty data passed with indices specified.")
   4279     raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-&gt; 4280         passed, implied))
   4281 
   4282 

ValueError: Shape of passed values is (4, 2), indices imply (4, 4)
</code></pre></div>
<h4 dir="auto">Problem description</h4>
<ul dir="auto">
<li>I see the same problem when <code class="notranslate">fun</code> returns a list (e.g. <code class="notranslate">[1,2]</code>) rather than tuple.</li>
<li>The error does not occur when apply is called with <code class="notranslate">axis=0</code>.</li>
<li>The error does not occur when I replace the Timestamp column with a column of integers.</li>
</ul>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">A pandas Series containing tuples:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="0    (1, 2)
1    (1, 2)
2    (1, 2)
3    (1, 2)
dtype: object"><pre class="notranslate"><code class="notranslate">0    (1, 2)
1    (1, 2)
2    (1, 2)
3    (1, 2)
dtype: object
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<p dir="auto">[paste the output of <code class="notranslate">pd.show_versions()</code> here below this line]</p>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.1.final.0<br>
python-bits: 64<br>
OS: Darwin<br>
OS-release: 16.7.0<br>
machine: x86_64<br>
processor: i386<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_GB.UTF-8<br>
LOCALE: en_GB.UTF-8</p>
<p dir="auto">pandas: 0.20.3<br>
pytest: 3.0.7<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.13.3<br>
scipy: 0.19.0<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.3.0<br>
numexpr: 2.6.2<br>
feather: 0.4.0<br>
matplotlib: 2.0.2<br>
openpyxl: 2.4.7<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.3<br>
bs4: 4.6.0<br>
html5lib: 0.9999999<br>
sqlalchemy: 1.1.9<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">Hello guys, I'm using the apply method with axis=1 argument and returning a list for each row. The weird thing is when the length of this list is equal to the number of features in the original dataframe, this apply returns another dataframe, and a series if anything else. I don't know if this is intended, but it was very unexpected.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(6, 3), columns=['A', 'B', 'C'])

ans1 = df.apply(lambda x: [1, 2, 3], axis=1)
ans2 = df.apply(lambda x: [1, 2], axis=1)

assert type(ans1) is pd.DataFrame
assert type(ans2) is pd.Series"><pre class="notranslate"><code class="notranslate">import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(6, 3), columns=['A', 'B', 'C'])

ans1 = df.apply(lambda x: [1, 2, 3], axis=1)
ans2 = df.apply(lambda x: [1, 2], axis=1)

assert type(ans1) is pd.DataFrame
assert type(ans2) is pd.Series
</code></pre></div>