{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/12945","repository_url":"https://api.github.com/repos/pydata/pandas","labels_url":"https://api.github.com/repos/pydata/pandas/issues/12945/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/12945/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/12945/events","html_url":"https://github.com/pydata/pandas/issues/12945","id":150114720,"number":12945,"title":"eval should handle ternary operator","user":{"login":"benjello","id":1175927,"avatar_url":"https://avatars.githubusercontent.com/u/1175927?v=3","gravatar_id":"","url":"https://api.github.com/users/benjello","html_url":"https://github.com/benjello","followers_url":"https://api.github.com/users/benjello/followers","following_url":"https://api.github.com/users/benjello/following{/other_user}","gists_url":"https://api.github.com/users/benjello/gists{/gist_id}","starred_url":"https://api.github.com/users/benjello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjello/subscriptions","organizations_url":"https://api.github.com/users/benjello/orgs","repos_url":"https://api.github.com/users/benjello/repos","events_url":"https://api.github.com/users/benjello/events{/privacy}","received_events_url":"https://api.github.com/users/benjello/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-21T15:50:47Z","updated_at":"2016-04-21T15:53:30Z","closed_at":null,"body":"It would be nice to be able to write ternary operator into expressions submitted to `eval`. \r\n\r\n#### Code Sample\r\n```python\r\ndf = pd.DataFrame({'a': range(10), 'b': range(10,20)})\r\ndf.eval('x = a if a < 5 else b', inplace = True)\r\ndf\r\n\r\nTraceback (most recent call last):\r\n\r\n  File \"<ipython-input-27-89e215206825>\", line 1, in <module>\r\n    df.eval('x = a if a < 5 else b')\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/core/frame.py\", line 2209, in eval\r\n    return _eval(expr, inplace=inplace, **kwargs)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/eval.py\", line 245, in eval\r\n    truediv=truediv)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 709, in __init__\r\n    self.terms = self.parse()\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 726, in parse\r\n    return self._visitor.visit(self.expr)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 310, in visit\r\n    return visitor(node, **kwargs)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 316, in visit_Module\r\n    return self.visit(expr, **kwargs)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 310, in visit\r\n    return visitor(node, **kwargs)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 494, in visit_Assign\r\n    return self.visit(node.value, **kwargs)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 310, in visit\r\n    return visitor(node, **kwargs)\r\n\r\n  File \"/home/benjello/.local/lib/python2.7/site-packages/pandas/computation/expr.py\", line 201, in f\r\n    \"implemented\".format(node_name))\r\n\r\nNotImplementedError: 'IfExp' nodes are not implemented\r\n```\r\n\r\n#### Expected Output\r\n```\r\n  a   b   x\r\n0  0  10   0\r\n1  1  11   1\r\n2  2  12   2\r\n3  3  13   3\r\n4  4  14   4\r\n5  5  15  15\r\n6  6  16  16\r\n7  7  17  17\r\n8  8  18  18\r\n9  9  19  19\r\n```\r\n\r\n#### output of ``pd.show_versions()``\r\n```\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 2.7.11.final.0\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 4.4.0-1-amd64\r\nmachine: x86_64\r\nprocessor: \r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: en_US.UTF-8\r\n\r\npandas: 0.18.0\r\nnose: 1.3.7\r\npip: 1.5.6\r\nsetuptools: 18.8\r\nCython: 0.23.4\r\nnumpy: 1.11.0\r\nscipy: 0.17.0\r\nstatsmodels: None\r\nxarray: None\r\nIPython: 4.0.3\r\nsphinx: 1.3.6\r\npatsy: 0.4.1\r\ndateutil: 2.4.2\r\npytz: 2015.7\r\nblosc: None\r\nbottleneck: None\r\ntables: 3.2.2\r\nnumexpr: 2.5.2\r\nmatplotlib: 1.5.1\r\nopenpyxl: 2.3.0\r\nxlrd: 0.9.4\r\nxlwt: 0.7.5\r\nxlsxwriter: 0.7.3\r\nlxml: 3.6.0\r\nbs4: 4.4.1\r\nhtml5lib: 0.999\r\nhttplib2: 0.9.1\r\napiclient: None\r\nsqlalchemy: None\r\npymysql: None\r\npsycopg2: None\r\njinja2: 2.8\r\nboto: None\r\n```"},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/212984212","html_url":"https://github.com/pydata/pandas/issues/12945#issuecomment-212984212","issue_url":"https://api.github.com/repos/pydata/pandas/issues/12945","id":212984212,"user":{"login":"jreback","id":953992,"avatar_url":"https://avatars.githubusercontent.com/u/953992?v=3","gravatar_id":"","url":"https://api.github.com/users/jreback","html_url":"https://github.com/jreback","followers_url":"https://api.github.com/users/jreback/followers","following_url":"https://api.github.com/users/jreback/following{/other_user}","gists_url":"https://api.github.com/users/jreback/gists{/gist_id}","starred_url":"https://api.github.com/users/jreback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreback/subscriptions","organizations_url":"https://api.github.com/users/jreback/orgs","repos_url":"https://api.github.com/users/jreback/repos","events_url":"https://api.github.com/users/jreback/events{/privacy}","received_events_url":"https://api.github.com/users/jreback/received_events","type":"User","site_admin":false},"created_at":"2016-04-21T15:53:30Z","updated_at":"2016-04-21T15:53:30Z","body":"this directly translates to a ``.where()`` so would kick it back out back to python land (which actually does execute it using ``numexpr`` internally. So from a syntactical point of view I guess its ok. Though remember these are vectorized expressions, not sure if that is clear to the user. I am only +0 as a result.\r\n"}}