{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/10463","labels_url":"https://api.github.com/repos/pydata/pandas/issues/10463/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/10463/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/10463/events","html_url":"https://github.com/pydata/pandas/issues/10463","id":91582007,"number":10463,"title":"Feature proposal: pandas vectorize decorator","user":{"login":"twiecki","id":674200,"avatar_url":"https://avatars.githubusercontent.com/u/674200?v=3","gravatar_id":"","url":"https://api.github.com/users/twiecki","html_url":"https://github.com/twiecki","followers_url":"https://api.github.com/users/twiecki/followers","following_url":"https://api.github.com/users/twiecki/following{/other_user}","gists_url":"https://api.github.com/users/twiecki/gists{/gist_id}","starred_url":"https://api.github.com/users/twiecki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twiecki/subscriptions","organizations_url":"https://api.github.com/users/twiecki/orgs","repos_url":"https://api.github.com/users/twiecki/repos","events_url":"https://api.github.com/users/twiecki/events{/privacy}","received_events_url":"https://api.github.com/users/twiecki/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-28T10:10:14Z","updated_at":"2015-06-28T10:23:49Z","closed_at":null,"body":"`numpy` has a very useful `vectorize` decorator: http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html that allows writing a function for scalars and then pass in arrays transparently. Under the hood, the function is called multiple times on subsets of the data.\r\n\r\nI'm currently writing code that operates on a `Series` object. Some of those functions can also be passed in DataFrames and still work the same while some would require special logic. I think a pandas vectorize decorator could be very useful for these cases. In my specific case, I can just write that myself easily but I thought I'd bring it up. Perhaps this already exists and I just don't know about it.  "},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/116252319","html_url":"https://github.com/pydata/pandas/issues/10463#issuecomment-116252319","issue_url":"https://api.github.com/repos/pydata/pandas/issues/10463","id":116252319,"user":{"login":"twiecki","id":674200,"avatar_url":"https://avatars.githubusercontent.com/u/674200?v=3","gravatar_id":"","url":"https://api.github.com/users/twiecki","html_url":"https://github.com/twiecki","followers_url":"https://api.github.com/users/twiecki/followers","following_url":"https://api.github.com/users/twiecki/following{/other_user}","gists_url":"https://api.github.com/users/twiecki/gists{/gist_id}","starred_url":"https://api.github.com/users/twiecki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twiecki/subscriptions","organizations_url":"https://api.github.com/users/twiecki/orgs","repos_url":"https://api.github.com/users/twiecki/repos","events_url":"https://api.github.com/users/twiecki/events{/privacy}","received_events_url":"https://api.github.com/users/twiecki/received_events","type":"User","site_admin":false},"created_at":"2015-06-28T10:23:49Z","updated_at":"2015-06-28T10:23:49Z","body":"Here is a quick and dirty fast-pass:\r\n```python\r\nfrom collections import OrderedDict\r\nimport pandas as pd\r\n\r\ndef vectorize(func):\r\n    def wrapper(df, *args, **kwargs):\r\n        if df.ndim == 1:\r\n            return func(df, *args, **kwargs)\r\n        elif df.ndim == 2:\r\n            # Call function on each column\r\n            out = OrderedDict()\r\n            multidim_output = False\r\n            for col in df:\r\n                out[col] = func(df[col], *args, **kwargs)\r\n                if isinstance(out[col], pd.Series):\r\n                    multidim_output = True\r\n            if multidim_output:\r\n                return pd.DataFrame(out)\r\n            else:\r\n                return pd.Series(out)\r\n\r\n    return wrapper\r\n```"}}