Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
ca0b39e1
Commit
ca0b39e1
authored
May 23, 2018
by
iLampard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix rank function and test_rank
parent
b3973859
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
rank.py
alphamind/data/rank.py
+1
-1
test_rank.py
alphamind/tests/data/test_rank.py
+11
-7
No files found.
alphamind/data/rank.py
View file @
ca0b39e1
...
...
@@ -23,7 +23,7 @@ def rank(x: np.ndarray, groups: Optional[np.ndarray]=None) -> np.ndarray:
start
=
0
for
diff_loc
in
index_diff
:
curr_idx
=
order
[
start
:
diff_loc
+
1
]
res
[
curr_idx
]
=
rankdata
(
x
[
curr_idx
])
.
astype
(
float
)
-
1.
res
[
curr_idx
]
=
(
rankdata
(
x
[
curr_idx
])
.
astype
(
float
)
-
1.
)
.
reshape
((
-
1
,
1
))
start
=
diff_loc
+
1
return
res
else
:
...
...
alphamind/tests/data/test_rank.py
View file @
ca0b39e1
...
...
@@ -29,10 +29,14 @@ class TestRank(unittest.TestCase):
np
.
testing
.
assert_array_less
(
0
,
arr_diff
)
def
test_rank_with_groups
(
self
):
data_rank
=
rank
(
self
.
x
,
groups
=
self
.
groups
)
df
=
pd
.
DataFrame
(
self
.
x
,
index
=
self
.
groups
)
expected_rank
=
df
.
groupby
(
level
=
0
)
.
apply
(
lambda
x
:
x
.
values
.
argsort
(
axis
=
0
)
.
argsort
(
axis
=
0
))
print
(
expected_rank
)
data
=
pd
.
DataFrame
(
data
=
{
'raw'
:
self
.
x
.
tolist
()},
index
=
self
.
groups
)
data
[
'rank'
]
=
rank
(
data
[
'raw'
],
groups
=
data
.
index
)
groups
=
dict
(
list
(
data
[
'rank'
]
.
groupby
(
level
=
0
)))
ret
=
[]
for
index
in
range
(
10
):
ret
.
append
(
groups
[
index
]
.
values
)
ret
=
np
.
concatenate
(
ret
)
.
reshape
(
-
1
,
1
)
expected_rank
=
data
[
'raw'
]
.
groupby
(
level
=
0
)
.
apply
(
lambda
x
:
x
.
values
.
argsort
(
axis
=
0
)
.
argsort
(
axis
=
0
))
expected_rank
=
np
.
concatenate
(
expected_rank
)
.
reshape
(
-
1
,
1
)
np
.
testing
.
assert_array_equal
(
ret
,
expected_rank
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment