Skip to content
Snippets Groups Projects
Commit c19ed89a authored by Bert Palm's avatar Bert Palm 🎇
Browse files

fixed iloc bug

parent 3be7f1e6
No related branches found
No related tags found
No related merge requests found
......@@ -61,14 +61,22 @@ class _Indexer:
dat_xloc = getattr(dat, xloc)
val = value[i] if iter else value
# a hashable rowkey (.xloc[3, c] = value) :
# loc: rowkey not present in self -> prevent that .loc create a new item
# loc: rowkey present in self -> OK
# iloc: OK (cannot set a new item)
if _is_hashable(rowkey):
# prevent setting a new value with .loc
if rowkey not in dat:
if xloc == 'loc' and rowkey not in dat:
raise KeyError(rowkey)
else:
# cannot set to empty series
if len(dat_xloc[rowkey]) == 0:
continue
# not a hashable rowkey (.xloc[[3,4], c] = value),
# so we can ask for a length, otherwise we might get a single value
# returned, that has no length. But we need to do this check, because,
# setting a value to an empty series, always fail.
# Nevertheless, if any key doesn't exist, the correct KeyError is thrown here,
# instead of later.
elif len(dat_xloc[rowkey]) == 0:
continue
dat_xloc[rowkey] = val
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment