Skip to content

Commit

Permalink
v4.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
chen-001 committed Mar 27, 2024
1 parent c2ad80b commit 816733d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pure_ocean_breeze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

__updated__ = "2023-07-18 14:49:23"
__version__ = "4.1.4"
__version__ = "4.1.5"
__author__ = "chenzongwei"
__author_email__ = "winterwinter999@163.com"
__url__ = "https://github.com/chen-001/pure_ocean_breeze"
Expand Down
30 changes: 26 additions & 4 deletions pure_ocean_breeze/jason/data/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,28 @@ def lu计算连续期数2(
continuous_ones = reset_cumsum * is_one
return continuous_ones.replace(0, nan_value)


def lu计算连续期数长度(s:Union[pd.Series,pd.DataFrame],final_mean=1)->Union[float,pd.Series,pd.DataFrame]:
if isinstance(s,pd.DataFrame):
return s.apply(lambda x:lu计算连续期数长度(x,final_mean))
else:
# 标识非 NaN 值
not_nan = s.notnull()

# 计算连续非 NaN 值的分组
groups = not_nan.ne(not_nan.shift()).cumsum()[not_nan]

# 计算每段连续非 NaN 值的长度
segment_lengths = groups.value_counts().sort_index()

# 计算平均长度
average_length = segment_lengths.mean()
if not final_mean:
return segment_lengths.values
else:
return segment_lengths.mean()


@do_on_dfs
def is_pos(s: Union[pd.Series, pd.DataFrame],zero_as_pos:bool=1) -> Union[pd.Series, pd.DataFrame]:
if zero_as_pos:
Expand All @@ -993,9 +1015,9 @@ def is_neg(s: Union[pd.Series, pd.DataFrame],zero_as_neg:bool=1) -> Union[pd.Ser
return np.sign(s).replace(0,np.nan).replace(1,np.nan).replace(-1,1)

@do_on_dfs
def get_pos_value(s: Union[pd.Series, pd.DataFrame],zero_as_pos:bool=1) -> Union[pd.Series, pd.DataFrame]:
return s * is_pos(s,zero_as_pos)
def get_pos_value(s: Union[pd.Series, pd.DataFrame],judge_sign:Union[float,pd.Series, pd.DataFrame],zero_as_pos:bool=1) -> Union[pd.Series, pd.DataFrame]:
return s * is_pos(s-judge_sign,zero_as_pos)

@do_on_dfs
def get_neg_value(s: Union[pd.Series, pd.DataFrame],zero_as_neg:bool=1) -> Union[pd.Series, pd.DataFrame]:
return s * is_neg(s,zero_as_neg)
def get_neg_value(s: Union[pd.Series, pd.DataFrame],judge_sign:Union[float,pd.Series, pd.DataFrame],zero_as_neg:bool=1) -> Union[pd.Series, pd.DataFrame]:
return s * is_neg(s-judge_sign,zero_as_neg)
2 changes: 1 addition & 1 deletion pure_ocean_breeze/jason/labor/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def get_icir_rankicir(cls, df):
return pd.DataFrame(
{"IC": [ic], "ICIR": [icir], "RankIC": [rankic], "RankICIR": [rankicir]},
index=["评价指标"],
),pd.DataFrame({"1-5rankic":[small_rankic],"1-5ICIR":[small_rankicir],"6-10RankIC":[big_rankic],"6-10ICIR":[big_rankicir]},index=["评价指标"]).T
),pd.DataFrame({"1-5RankIC":[small_rankic],"1-5ICIR":[small_rankicir],"6-10RankIC":[big_rankic],"6-10ICIR":[big_rankicir]},index=["评价指标"]).T

def get_ic_icir_and_rank(cls, df):
"""计算IC、ICIR、RankIC、RankICIR"""
Expand Down

0 comments on commit 816733d

Please sign in to comment.