pydata/pandas — pull request #2757 by dandavison (2013-01-25 21:34:44+00:00)
Title: `DataFrame.from_items` clean-up

- Improve docstrings and error messages
- Convert final `elif` to `else`

### Testing
I checked that the `from_items` method was working as usual, and that the new docstrings and error messages looked OK, in the following session.

```python
>>> pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])])

a b
0 1 3
1 2 4

>>> pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])], orient='columns')

a b
0 1 3
1 2 4

>>> pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])], orient='index')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])], orient='index')

/Users/dan/lib/python/pandas/pandas/core/frame.pyc in from_items(cls, items, columns, orient)
1144 elif orient == 'index':
1145 if columns is None:
-> 1146 raise ValueError("Must pass columns with orient='index'")
1147
1148 keys = _ensure_index(keys)

ValueError: Must pass columns with orient='index'

>>> pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])], orient='index', columns=['col1', 'col2'])

col1 col2
a 1 2
b 3 4

>>> pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])], orient='indexXXX', columns=['col1', 'col2']) ---------------------------------------------------------------------------ValueError Traceback (most recent call last) in ()----> 1 pd.DataFrame.from_items([('a', [1,2]), ('b', [3,4])], orient='indexXXX', columns=['col1', 'col2'])/Users/dan/lib/python/pandas/pandas/core/frame.pyc in from_items(cls, items, columns, orient)
1152 return cls._from_arrays(data, columns, keys)
1153 else: # pragma: no cover
-> 1154 raise ValueError("'orient' must be either 'columns' or 'index'")
1155
1156 @classmethod

ValueError: 'orient' must be either 'columns' or 'index'

>>> pd.DataFrame.from_items?
Type: instancemethod
String Form:>
File: /Users/dan/lib/python/pandas/pandas/core/frame.py
Definition: pd.DataFrame.from_items(cls, items, columns=None, orient='columns')
Docstring:
Convert (key, value) pairs to DataFrame. The keys will be the axis
index (usually the columns, but depends on the specified
orientation). The values should be arrays or Series.

Parameters
----------
items : sequence of (key, value) pairs
Values should be arrays or Series.
columns : sequence of column labels, optional
Must be passed if orient='index'.
orient : {'columns', 'index'}, default 'columns'
The "orientation" of the data. If the keys of the
input correspond to column labels, pass 'columns'
(default). Otherwise if the keys correspond to the index,
pass 'index'.

Returns
-------
frame : DataFrame

>>>
```