Skip to content

Commit

Permalink
Better error message for unicode formula in PY2
Browse files Browse the repository at this point in the history
Closes pydata#56
  • Loading branch information
has2k1 committed Oct 18, 2015
1 parent b2ff88d commit cc97d0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 2 additions & 5 deletions patsy/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ def _try_incr_builders(formula_like, data_iter_maker, eval_env,
data_iter_maker,
eval_env,
NA_action)
else:
# check if formula_like is another string type (which might be unsupported)
if isinstance(formula_like, string_types):
raise PatsyError("Unsupported string type for formula (e.g., unicode in Python 2.X).")
return None
if not six.PY3 and isinstance(formula_like, unicode):
raise PatsyError("Unicode formula not support in Python 2")

def incr_dbuilder(formula_like, data_iter_maker, eval_env=0, NA_action="drop"):
"""Construct a design matrix builder incrementally from a large data set.
Expand Down
9 changes: 9 additions & 0 deletions patsy/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Exhaustive end-to-end tests of the top-level API.

import sys
import six
import __future__
import numpy as np
from nose.tools import assert_raises
Expand Down Expand Up @@ -743,3 +744,11 @@ def test_C_and_pandas_categorical():
[[1, 0],
[1, 1],
[1, 0]])

def test_unicode_py2():
if six.PY3:
return

data = {"x": [1, 2], "y": [1, 2]}
formula_like = u"y ~ x"
assert_raises(PatsyError, dmatrix, formula_like, data)

0 comments on commit cc97d0d

Please sign in to comment.