Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dios
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RDM
dios
Commits
07cee786
Commit
07cee786
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
pd.Series.loc bug-fix
parent
46189e42
No related branches found
No related tags found
1 merge request
!2
Develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dios/dios.py
+15
-15
15 additions, 15 deletions
dios/dios.py
dios/locator.py
+1
-1
1 addition, 1 deletion
dios/locator.py
with
16 additions
and
16 deletions
dios/dios.py
+
15
−
15
View file @
07cee786
...
...
@@ -123,7 +123,7 @@ class DictOfSeries:
@property
def
columns
(
self
):
return
self
.
_data
.
index
return
self
.
_data
.
index
.
copy
()
@columns.setter
def
columns
(
self
,
newindex
):
...
...
@@ -179,7 +179,7 @@ class DictOfSeries:
# `s = series([5,6], index=['a','b'])`
# s[1] returns 6 instead of raising a KeyError
raise
KeyError
(
f
"'
{
key
}
'"
)
new
=
self
.
_data
[
key
]
new
=
self
.
_data
.
loc
[
key
]
else
:
keys
,
ixs
,
ixalign
=
self
.
_unpack_key
(
key
)
new
=
self
.
copy_empty
()
...
...
@@ -188,10 +188,10 @@ class DictOfSeries:
return
new
def
_get_item
(
self
,
key
,
ix
,
ixalign
):
ser
=
self
.
_data
[
key
]
ser
=
self
.
_data
.
loc
[
key
]
if
ixalign
:
ix
=
ser
.
index
.
intersection
(
ix
.
index
)
return
ser
[
ix
]
return
ser
.
loc
[
ix
]
def
__setitem__
(
self
,
key
,
value
):
"""
dios[x] = y
...
...
@@ -232,7 +232,7 @@ class DictOfSeries:
if
ixalign
:
ix
=
ser
.
index
.
intersection
(
ix
.
index
)
if
isinstance
(
right
,
pd
.
Series
):
left
=
ser
[
ix
]
left
=
ser
.
loc
[
ix
]
right
,
ix
=
align_index_by_policy
(
left
,
right
)
ser
.
loc
[
ix
]
=
right
...
...
@@ -294,14 +294,14 @@ class DictOfSeries:
if
not
isinstance
(
key
,
pd
.
Series
):
raise
ValueError
(
"
Must pass Series with boolean values only
"
)
keys
=
self
.
columns
indexer
,
ixalign
=
[
key
[
key
]]
*
len
(
keys
),
True
indexer
,
ixalign
=
[
key
.
loc
[
key
]]
*
len
(
keys
),
True
elif
is_dios_like
(
key
):
keys
=
self
.
columns
.
intersection
(
key
.
columns
).
to_list
()
for
k
in
keys
:
if
not
is_bool_indexer
(
key
[
k
]):
raise
ValueError
(
"
Must pass DictOfSeries with boolean values only
"
)
indexer
,
ixalign
=
[
(
key
[
k
]
)
[
key
[
k
]]
for
k
in
keys
],
True
indexer
,
ixalign
=
[
key
[
k
]
.
loc
[
key
[
k
]]
for
k
in
keys
],
True
# slice
# -----
# slices always work rows too, but never fail and
...
...
@@ -438,8 +438,8 @@ class DictOfSeries:
def
_op1
(
self
,
op
):
new
=
self
.
copy_empty
()
try
:
for
k
in
self
:
new
[
k
]
=
op
(
self
.
_data
[
k
])
for
k
in
self
.
columns
:
new
[
k
]
=
op
(
self
.
_data
.
loc
[
k
])
except
Exception
as
e
:
raise
type
(
e
)(
f
"'
{
OP_MAP
[
op
]
}
dios
'
failed:
"
+
str
(
e
))
from
e
return
new
...
...
@@ -456,23 +456,23 @@ class DictOfSeries:
if
is_dios_like
(
other
):
raiseif
(
set
(
other
)
!=
set
(
self
),
'
#keys
'
)
for
k
in
self
.
columns
:
left
,
right
=
self
.
_data
[
k
],
other
[
k
]
left
,
right
=
self
.
_data
.
loc
[
k
],
other
[
k
]
yield
k
,
op
(
*
doalign
(
left
,
right
))
elif
isinstance
(
other
,
pd
.
Series
):
for
k
in
self
.
columns
:
left
,
right
=
self
.
_data
[
k
],
other
left
,
right
=
self
.
_data
.
loc
[
k
],
other
yield
k
,
op
(
*
doalign
(
left
,
right
))
elif
is_dict_like
(
other
):
raiseif
(
set
(
other
)
!=
set
(
self
),
'
#keys
'
)
for
k
in
self
.
columns
:
yield
k
,
op
(
self
.
_data
[
k
],
other
[
k
])
yield
k
,
op
(
self
.
_data
.
loc
[
k
],
other
[
k
])
elif
is_nested_list_like
(
other
):
raiseif
(
len
(
other
)
!=
len
(
self
),
'
length
'
)
for
i
,
k
in
enumerate
(
self
.
columns
):
yield
k
,
op
(
self
.
_data
[
k
],
other
[
i
])
yield
k
,
op
(
self
.
_data
.
loc
[
k
],
other
[
i
])
elif
is_scalar
(
other
)
or
is_list_like
(
other
):
for
k
in
self
.
columns
:
yield
k
,
op
(
self
.
_data
[
k
],
other
)
yield
k
,
op
(
self
.
_data
.
loc
[
k
],
other
)
else
:
raise
NotImplementedError
...
...
@@ -539,7 +539,7 @@ class DictOfSeries:
# the item from the dict, by our mother class.
return
self
.
_data
[
k
]
else
:
return
self
.
_data
[
k
].
copy
()
return
self
.
_data
.
loc
[
k
].
copy
()
for
k
in
self
.
columns
:
v
=
f
(
getobj
(
k
,
inplace
),
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
dios/locator.py
+
1
−
1
View file @
07cee786
...
...
@@ -107,7 +107,7 @@ class _iLocIndexer(_Indexer):
def
_set_item
(
self
,
key
,
ix
,
right
,
ixalign
=
False
):
# we do use loc instead of iloc as we get real keys.
# this works, because keys keep sorted if they come
# from an
index from and
series (doesn't work with df)
# from an series
-index
(doesn't work with df
-index
)
ser
=
self
.
_data
[
key
]
if
ixalign
:
ix
=
ser
.
index
.
intersection
(
ix
.
index
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment