{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/20347","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20347/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20347/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20347/events","html_url":"https://github.com/pandas-dev/pandas/pull/20347","id":305189209,"number":20347,"title":"API: str.cat will align on Series","user":{"login":"h-vetinari","id":33685575,"avatar_url":"https://avatars1.githubusercontent.com/u/33685575?v=4","gravatar_id":"","url":"https://api.github.com/users/h-vetinari","html_url":"https://github.com/h-vetinari","followers_url":"https://api.github.com/users/h-vetinari/followers","following_url":"https://api.github.com/users/h-vetinari/following{/other_user}","gists_url":"https://api.github.com/users/h-vetinari/gists{/gist_id}","starred_url":"https://api.github.com/users/h-vetinari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/h-vetinari/subscriptions","organizations_url":"https://api.github.com/users/h-vetinari/orgs","repos_url":"https://api.github.com/users/h-vetinari/repos","events_url":"https://api.github.com/users/h-vetinari/events{/privacy}","received_events_url":"https://api.github.com/users/h-vetinari/received_events","type":"User","site_admin":false},"labels":[{"id":35818298,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/API%20Design","name":"API Design","color":"AD7FA8","default":false},{"id":57522093,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/Strings","name":"Strings","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2018-03-14T14:44:38Z","updated_at":"2018-03-19T12:14:03Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/pandas-dev/pandas/pulls/20347","html_url":"https://github.com/pandas-dev/pandas/pull/20347","diff_url":"https://github.com/pandas-dev/pandas/pull/20347.diff","patch_url":"https://github.com/pandas-dev/pandas/pull/20347.patch"},"body":"Fixes issue #18657, fixed existing tests, added new test; all pass.\r\n\r\nAfter I pushed everything and thought about it some more, I realised that one may argue about the default alignment-behavior, and whether it should be changed to `join=outer`. The behavior as implemented is compatible with the current requirement that everything be of the same length. To me, it is more intuitive that the concatenated `other` is added to the current series without enlarging it, but I can also see the argument why that restriction is unnecessary.\r\n\r\nPS. This is my first PR, tried to follow all the rules. Sorry if I overlooked something."},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/374191773","html_url":"https://github.com/pandas-dev/pandas/pull/20347#issuecomment-374191773","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/20347","id":374191773,"user":{"login":"h-vetinari","id":33685575,"avatar_url":"https://avatars1.githubusercontent.com/u/33685575?v=4","gravatar_id":"","url":"https://api.github.com/users/h-vetinari","html_url":"https://github.com/h-vetinari","followers_url":"https://api.github.com/users/h-vetinari/followers","following_url":"https://api.github.com/users/h-vetinari/following{/other_user}","gists_url":"https://api.github.com/users/h-vetinari/gists{/gist_id}","starred_url":"https://api.github.com/users/h-vetinari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/h-vetinari/subscriptions","organizations_url":"https://api.github.com/users/h-vetinari/orgs","repos_url":"https://api.github.com/users/h-vetinari/repos","events_url":"https://api.github.com/users/h-vetinari/events{/privacy}","received_events_url":"https://api.github.com/users/h-vetinari/received_events","type":"User","site_admin":false},"created_at":"2018-03-19T12:14:03Z","updated_at":"2018-03-19T12:14:03Z","author_association":"NONE","body":"@jorisvandenbossche \r\npandas advertises itself as (http://pandas.pydata.org/pandas-docs/stable/):\r\n> Automatic and explicit **data alignment**: objects can be explicitly aligned to a set of labels, or the user can simply ignore the labels and let Series, DataFrame, etc. automatically align the data for you in computations\r\n\r\nTherefore, I do not think that uses should have to align their Series themselves - the expectation that pandas evokes everywhere else is that things will be aligned automatically (in fact, I didn't know about ``Series.align`` for a long time, because it was never necessary). The easiest reference for me is something like boolean operations,\r\n```\r\nIn [0]: s = pd.Series(['a', 'b'])\r\nIn [1]: t = pd.Series(['a', 'b'], index=[1, 2])\r\nIn [2]: s.astype(bool) & t.astype(bool)\r\nOut[2]:\r\n0    False\r\n1     True\r\n2    False\r\ndtype: bool\r\n```\r\nbut also things like ``.eq``, ``.merge``, etc.\r\n\r\nI agree that ``join='left'`` is a good default behavior for ``str.cat``, but it is very important IMHO to allow the other options as well (see also the original issue #18657). And since there are *no other methods*  for the ``.str``-accessor that take another Series as an argument, this does not break any cosistency. Therefore, the proposal would be:\r\n```\r\nIn [3]: s.str.cat(t, align=True, na_rep='-')\r\nOut[3]: \r\n0    a-\r\n1    ba\r\ndtype: object\r\nIn [4]: s.str.cat(t, align=True, join='outer', na_rep='-')\r\nOut[4]: \r\n0    a-\r\n1    ba\r\n2    -b\r\ndtype: object\r\n```\r\n\r\nA bit further up, @TomAugspurger agreed with the ``join``-keyword as well.\r\n\r\n> But, maybe we can be just more restrictive here. Eg disallow different types (either only series, or either only lists/arrays), might simplify things?\r\n\r\nI don't think that this would make things easier -- assuming we don't want to break existing code like\r\n`` s.str.cat([['A', 'B'], ['1', '2']])``. Basically all of the complexity comes from allowing lists of Series and arrays, but since those are legal currently, it's a strong argument to keep that, no?\r\n\r\nAnd as soon as the logic is there to deal with such mixed lists (i.e. align arrays with the calling Series and proceed from there), then the other additions I made are really cheap:\r\nMy thought was, \"if we allow list of Series, why not DataFrames?\"\r\nSame for two-dimensional ndarrays and an iterable as the outer container. Those can easily be removed, but I consider them cheap (in terms of line-count) and *useful* additions to the capability that is already needed to deal with the list of Series/arrays."}}
{"actor":{"display_login":"h-vetinari"}}