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
8264b254
Commit
8264b254
authored
4 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
added where() and mask()
parent
922bafe0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dios/dios.py
+93
-0
93 additions, 0 deletions
dios/dios.py
with
93 additions
and
0 deletions
dios/dios.py
+
93
−
0
View file @
8264b254
...
...
@@ -5,6 +5,7 @@ from .lib import _find_least_common_itype
import
functools
as
ftools
import
pandas
as
pd
import
pandas.core.dtypes.common
as
pdcom
import
pandas.core.common
as
pdcorecom
import
numpy
as
np
...
...
@@ -582,6 +583,98 @@ class DictOfSeries(_DiosBase):
data
=
self
.
for_each
(
'
astype
'
,
dtype
=
dtype
,
copy
=
copy
,
errors
=
errors
)
return
DictOfSeries
(
data
=
data
,
itype
=
self
.
itype
,
cast_policy
=
self
.
_policy
,
fastpath
=
True
)
def
_mask_or_where
(
self
,
cond
,
other
=
np
.
nan
,
inplace
=
False
,
mask
=
True
):
"""
helper to mask/where
"""
data
=
self
if
inplace
else
self
.
copy
()
if
callable
(
other
):
other
=
other
(
data
)
if
callable
(
cond
):
cond
=
cond
(
data
)
# if DictOfSeries is bool,
# is already checked in aloc
elif
not
_is_dios_like
(
cond
):
if
not
pdcorecom
.
is_bool_indexer
(
cond
):
raise
ValueError
(
"
Object with boolean entries only expected for the condition
"
)
if
mask
:
data
.
aloc
[
cond
]
=
other
else
:
data
.
aloc
[
~
cond
]
=
other
if
inplace
:
return
None
return
data
def
where
(
self
,
cond
,
other
=
np
.
nan
,
inplace
=
False
):
"""
Replace values where the condition is False.
Parameters
----------
cond : bool DictOfSeries, Series, array-like, or callable
Where cond is True, keep the original value. Where False, replace
with corresponding value from other. If cond is callable, it is computed
on the DictOfSeries and should return boolean DictOfSeries or array.
The callable must not change input DictOfSeries (though dios doesn’t check it).
If cond is a bool Series, every column is (row-)aligned against it, before the
boolean values are evaluated. Missing indices are treated like False values.
other : scalar, Series, DictOfSeries, or callable
Entries where cond is False are replaced with corresponding value from other.
If other is callable, it is computed on the DictOfSeries and should return scalar
or DictOfSeries. The callable must not change input DictOfSeries (though dios doesn’t check it).
If other is a Series, every column is (row-)aligned against it, before the values
are written. NAN
'
s are written for missing indices.
inplace : bool, default False
Whether to perform the operation in place on the data.
Returns
-------
DictOfSeries
See Also
--------
mask: Mask data where condition is True
"""
return
self
.
_mask_or_where
(
cond
=
cond
,
other
=
other
,
inplace
=
inplace
,
mask
=
False
)
def
mask
(
self
,
cond
,
other
=
np
.
nan
,
inplace
=
False
):
"""
Replace values where the condition is True.
Parameters
----------
cond : bool DictOfSeries, Series, array-like, or callable
Where cond is False, keep the original value. Where True, replace
with corresponding value from other. If cond is callable, it is computed
on the DictOfSeries and should return boolean DictOfSeries or array.
The callable must not change input DictOfSeries (though dios doesn’t check it).
If cond is a bool Series, every column is (row-)aligned against it, before the
boolean values are evaluated. Missing indices are treated like False values.
other : scalar, Series, DictOfSeries, or callable
Entries where cond is True are replaced with corresponding value from other.
If other is callable, it is computed on the DictOfSeries and should return scalar
or DictOfSeries. The callable must not change input DictOfSeries (though dios doesn’t check it).
If other is a Series, every column is (row-)aligned against it, before the values
are written. NAN
'
s are written for missing indices.
inplace : bool, default False
Whether to perform the operation in place on the data.
Returns
-------
DictOfSeries
See Also
--------
mask: Mask data where condition is False
"""
return
self
.
_mask_or_where
(
cond
=
cond
,
other
=
other
,
inplace
=
inplace
,
mask
=
True
)
def
memory_usage
(
self
,
index
=
True
,
deep
=
False
):
return
self
.
for_each
(
pd
.
Series
.
memory_usage
,
index
=
index
,
deep
=
deep
).
sum
()
...
...
This diff is collapsed.
Click to expand it.
Bert Palm
🎇
@palmb
mentioned in issue
#23
·
4 years ago
mentioned in issue
#23
mentioned in issue #23
Toggle commit list
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