-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
When trying to use the patsy builtin identity matrix I()
adding two features the numpy recarray throws an error while the pandas equivalent executes without a problem. Code to reproduce the error:
from patsy import dmatrix
import numpy as np
import pandas as pd
recarray = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])
df = pd.DataFrame.from_records(recarray)
result_df = dmatrix("I(x+y)-1",df)
result_rec = dmatrix("I(x+y)-1",recarray)
python 3.6.5
patsy 0.5.0
pandas 0.23.4
numpy 1.14.1
traceback:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/patsy/compat.py", line 36, in call_and_wrap_exc
return f(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/patsy/eval.py", line 166, in eval
+ self._namespaces))
File "<string>", line 1, in <module>
File "/anaconda3/lib/python3.6/site-packages/patsy/eval.py", line 48, in __getitem__
return d[key]
File "/anaconda3/lib/python3.6/site-packages/patsy/eval.py", line 48, in __getitem__
return d[key]
ValueError: no field of name I
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_run_in_console.py", line 52, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/daviddejong/PycharmProjects/quick_test/patsy_test.py", line 7, in <module>
result_rec = dmatrix("I(x+y)-1",recarray)
File "/anaconda3/lib/python3.6/site-packages/patsy/highlevel.py", line 291, in dmatrix
NA_action, return_type)
File "/anaconda3/lib/python3.6/site-packages/patsy/highlevel.py", line 165, in _do_highlevel_design
NA_action)
File "/anaconda3/lib/python3.6/site-packages/patsy/highlevel.py", line 70, in _try_incr_builders
NA_action)
File "/anaconda3/lib/python3.6/site-packages/patsy/build.py", line 696, in design_matrix_builders
NA_action)
File "/anaconda3/lib/python3.6/site-packages/patsy/build.py", line 443, in _examine_factor_types
value = factor.eval(factor_states[factor], data)
File "/anaconda3/lib/python3.6/site-packages/patsy/eval.py", line 566, in eval
data)
File "/anaconda3/lib/python3.6/site-packages/patsy/eval.py", line 551, in _eval
inner_namespace=inner_namespace)
File "/anaconda3/lib/python3.6/site-packages/patsy/compat.py", line 43, in call_and_wrap_exc
exec("raise new_exc from e")
File "<string>", line 1, in <module>
patsy.PatsyError: Error evaluating factor: ValueError: no field of name I
I(x+y)-1
^^^^^^
ForceBru
Metadata
Metadata
Assignees
Labels
No labels