Repository navigation
Closed
Description
Just exploring patsy seriously for the first time -- instant love affair! Thanks a lot!
Found one little bug (patsy 0.2.0, pandas 0.12) as described in issue title. Minimal example taken from the first line of the docs and slightly adjusted to reproduce the behaviour. Seems like the missing data should be dropped from some index but is not. Or am I missing something?
In [1]: from patsy import dmatrix, demo_data
In [2]: import pandas as pd
In [3]: import numpy as np
In [4]: data = pd.DataFrame(demo_data("a", "b", "x1", "x2", "y"))
In [5]: data['a'].iloc[0] = np.nan
In [6]: dmatrix('a', data, return_type='dataframe')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-3ab0bd40ae1e> in <module>()
----> 1 dmatrix('a', data, return_type='dataframe')
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/patsy/highlevel.py in dmatrix(formula_like, data, eval_env, NA_action, return_type)
276 eval_env = EvalEnvironment.capture(eval_env, reference=1)
277 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
--> 278 NA_action, return_type)
279 if lhs.shape[1] != 0:
280 raise PatsyError("encountered outcome variables for a model "
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/patsy/highlevel.py in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
154 return build_design_matrices(builders, data,
155 NA_action=NA_action,
--> 156 return_type=return_type)
157 else:
158 # No builders, but maybe we can still get matrices
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/patsy/build.py in build_design_matrices(builders, data, NA_action, return_type, dtype)
954 matrices[i] = pandas.DataFrame(matrix,
955 columns=di.column_names,
--> 956 index=pandas_index)
957 matrices[i].design_info = di
958 return matrices
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
413 else:
414 mgr = self._init_ndarray(data, index, columns, dtype=dtype,
--> 415 copy=copy)
416 elif isinstance(data, list):
417 if len(data) > 0:
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/pandas/core/frame.py in _init_ndarray(self, values, index, columns, dtype, copy)
559 columns = _ensure_index(columns)
560
--> 561 return create_block_manager_from_blocks([ values.T ], [ columns, index ])
562
563 def _wrap_array(self, arr, axes, copy=False):
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/pandas/core/internals.py in create_block_manager_from_blocks(blocks, axes)
2233 blocks = [ getattr(b,'values',b) for b in blocks ]
2234 tot_items = sum(b.shape[0] for b in blocks)
-> 2235 construction_error(tot_items,blocks[0].shape[1:],axes)
2236
2237 def create_block_manager_from_arrays(arrays, names, axes):
/home/xxx/anaconda/envs/py33/lib/python3.3/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes)
2215 raise ValueError("Shape of passed values is %s, indices imply %s" % (
2216 tuple(map(int, [tot_items] + list(block_shape))),
-> 2217 tuple(map(int, [len(ax) for ax in axes]))))
2218
2219
ValueError: Shape of passed values is (0, 8), indices imply (0, 7)
Metadata
Metadata
Assignees
Labels
No labels
Activity
njsmith commentedon Aug 21, 2013
(Not sure if github sends notifications when I close a bug automatically via a commit, so, just in case: this bug is fixed in the just-released patsy 0.2.1.)
hmgaudecker commentedon Aug 22, 2013
On 21.08.13 23:13, njsmith wrote: