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
c014a0df
Commit
c014a0df
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
fine new properties / methods
parent
14ffb61c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dios/dios.py
+54
-6
54 additions, 6 deletions
dios/dios.py
with
54 additions
and
6 deletions
dios/dios.py
+
54
−
6
View file @
c014a0df
...
...
@@ -13,7 +13,6 @@ import numpy as np
import
operator
as
op
import
functools
as
ftools
import
itertools
import
pandas.core.dtypes.common
as
dcom
...
...
@@ -127,9 +126,8 @@ class DictOfSeries:
if
data
is
not
None
:
self
.
_init_insert_data
(
data
,
columns
)
# NOTE: self._data contain nans at locations
# where no data was present, but a column-name
# was given
# self._data contain nans at locations, where no
# data was present, but a column-name was given
if
itype
is
None
:
self
.
_itype
=
_find_least_common_itype
(
self
.
_data
.
dropna
())
...
...
@@ -189,6 +187,48 @@ class DictOfSeries:
def
columns
(
self
,
cols
):
self
.
_data
.
index
=
cols
@property
def
indexes
(
self
):
"""
Return pd.series with the indexes.
"""
return
self
.
_fast_apply
(
'
index
'
)
def
index_of
(
self
,
method
=
'
all
'
):
"""
Return an single index with indices from all columns.
parameter
----------
method: string
-
'
all
'
: get all indices from all columns
-
'
union
'
: alias for
'
all
'
-
'
shared
'
: get indices that are present in every columns
-
'
intersection
'
: alias for
'
shared
'
-
'
uniques
'
: get indices that are only present in a single column
-
'
non-uniques
'
: get indices that are present in more than one column
Note
----
The returned index never contains duplicates.
"""
indexes
=
self
.
indexes
if
len
(
indexes
)
<=
1
:
return
indexes
.
squeeze
()
if
method
in
[
'
union
'
,
'
all
'
]:
res
=
ftools
.
reduce
(
pd
.
Index
.
union
,
indexes
)
elif
method
==
[
'
intersection
'
,
'
shared
'
]:
res
=
ftools
.
reduce
(
pd
.
Index
.
intersection
,
indexes
)
elif
method
in
[
'
uniques
'
,
'
non-uniques
'
]:
res
=
ftools
.
reduce
(
pd
.
Index
.
append
,
indexes
)
res
=
res
.
value_counts
(
sort
=
False
,
dropna
=
False
)
if
method
==
'
uniques
'
:
res
=
res
[
res
==
1
].
index
else
:
res
=
res
[
res
>
1
].
index
else
:
raise
ValueError
(
method
)
return
res
if
res
.
is_unique
else
res
.
unique
()
@property
def
itype
(
self
):
return
self
.
_itype
...
...
@@ -352,6 +392,14 @@ class DictOfSeries:
raise
ValueError
(
axis
)
@property
def
size
(
self
):
return
self
.
lengths
.
sum
()
@property
def
lengths
(
self
):
return
self
.
_data
.
apply
(
len
)
def
__len__
(
self
):
return
len
(
self
.
columns
)
...
...
@@ -486,8 +534,8 @@ class DictOfSeries:
if
not
isinstance
(
d
,
pd
.
Series
):
d
=
pd
.
Series
(
d
)
data
.
at
[
c
]
=
d
new
=
DictOfSeries
(
data
=
data
,
itype
=
MixedItype
,
fastpath
=
True
)
new
.
_itype
=
new
.
__find_least_common_itype
(
)
itype
=
_find_least_common_itype
(
data
)
new
=
DictOfSeries
(
data
=
data
,
itype
=
itype
,
fastpath
=
True
)
else
:
new
=
pd
.
Series
(
data
=
new
,
index
=
self
.
columns
)
else
:
...
...
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