-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API/REGR: construction of Series with scalar-like / len-1 lists #20391
Comments
So the question is, do we want to keep the special case of len-1 lists being broadcasted? (so add that behaviour back) And if not, do we have others ways to ensure pandas regards something as a scalar? |
no this was disallowed as it’s wrong - you can broadcast a scalar but not a list (when u specify and index) - you have to raise here as you don’t know what’s correct |
hmm, yeah, I can of course easily in geopandas create a list with the correct length if the index is specified, instead of always a list of 1 element |
Given we apparently relied on this behaviour on purpose for geopandas, I added a notice of this change to the API changes: #20392 |
its already there: https://github.com/pandas-dev/pandas/pull/19714/files |
That's another issue (specific about Categorical, and in the bug fixes section). At least that was the actual bug being solved, the thing I raise here was a side-effect of the fix. |
At geopandas some tests started failing with pandas master:
previously this replicated the single point multiple times, just as
pd.Series(1, index=['a', 'b', 'c', 'd'])
gives a Series with four 1's.This is related to #19714, which removed the broadcasting of 1-length lists in the Series constructor (pd.Series([1], index=['a', 'b', 'c', 'd'])
The reason that geopandas converted the geometry to single element lists, is because geometries are convertable to array (and some are also iterable), and hence not seen as a 'scalar' by pandas (added 4 years ago: geopandas/geopandas#70).
It still works when you do not pass an index:
Note there is also some inconsistency within pandas itself:
(because in the first case when no index is specifed,
p
is converted to[p]
before passing it to_sanitize_array
, it works, but in the seconds case_sanitize_array
converts the pointp
tonp.array[1, 2])
(array of its coordinates))The text was updated successfully, but these errors were encountered: