AspectJ:如何替换现有注释(AspectJ: How to replace an existing annotation)
使用AspectJ,如何替换现有注释?
我有以下代码
declare @method : @Test * *(..) : @Test(timeout=10);
这会在每个测试方法上生成以下错误:
... already has an annotation of type org.junit.Test, cannot add a second instance [Xlint:elementAlreadyAnnotated]
当然,错误是有道理的,但是语法是什么,“从拥有它的所有方法中删除
@Test
注释。然后将其替换为@Test(timeout=10)
”Using AspectJ, how do you replace an existing annotation?
I have the following code
declare @method : @Test * *(..) : @Test(timeout=10);
Which generates the following error on every test method:
... already has an annotation of type org.junit.Test, cannot add a second instance [Xlint:elementAlreadyAnnotated]
Of course, the error makes sense but what is the syntax to say, "remove the
@Test
annotation from all methods that have it. Then replace it with@Test(timeout=10)
"
原文:https://stackoverflow.com/questions/4106187
最满意答案
它不一定是最漂亮的,但在过去我做过类似的事情
df = pd.read_csv("vd.csv", sep="\s+") d2 = pd.melt(df, id_vars="day") d2["sample"] = d2.groupby(["variable", "day"])["day"].rank("first") d3 = d2.pivot_table(index=["variable", "sample"], columns="day")
这使
>>> d3 value day 1 2 3 4 5 variable sample var1 1 -0.001285 -0.001331 -0.001362 -0.001394 -0.001467 2 -0.001310 -0.001360 -0.001372 -0.001431 -0.001491 var2 1 0.001381 0.001375 0.001444 0.001437 0.001433 2 0.001377 0.001430 0.001441 0.001434 0.001432 var3 1 1.022781 1.022477 1.022280 1.022017 1.021749 2 1.022626 1.022385 1.022161 1.021908 1.021602 [6 rows x 5 columns]
(虽然老实说,我认为安迪的方式更加流畅。我会把它留在这里,因为过去在更难的情况下融化修改枢轴模式对我来说非常有用。)
It's not necessarily the prettiest, but in the past I've done things like
df = pd.read_csv("vd.csv", sep="\s+") d2 = pd.melt(df, id_vars="day") d2["sample"] = d2.groupby(["variable", "day"])["day"].rank("first") d3 = d2.pivot_table(index=["variable", "sample"], columns="day")
which gives
>>> d3 value day 1 2 3 4 5 variable sample var1 1 -0.001285 -0.001331 -0.001362 -0.001394 -0.001467 2 -0.001310 -0.001360 -0.001372 -0.001431 -0.001491 var2 1 0.001381 0.001375 0.001444 0.001437 0.001433 2 0.001377 0.001430 0.001441 0.001434 0.001432 var3 1 1.022781 1.022477 1.022280 1.022017 1.021749 2 1.022626 1.022385 1.022161 1.021908 1.021602 [6 rows x 5 columns]
(Although to be honest, I think Andy's way is slicker. I'll leave this here though because the melt-modify-pivot pattern has proved pretty useful for me in the past in harder cases.)
相关问答
更多-
2017回答 - 熊猫0.20:.ix已被弃用。 使用.loc 请参阅文档中的弃用 .loc使用基于标签的索引来选择行和列。 标签是索引或列的值。 .loc包含最后一个元素。 假设我们有一个包含以下列的DataFrame: foo , bar , quz , ant , cat , sat , dat 。 # selects all rows and all columns beginning at 'foo' up to and including 'ant' df.loc[:, 'foo':'sat'] ...
-
您可以尝试以下几种方法: l = len(df) for i in range(len): if df.loc[i, 'Average_Diff'] == int(2): df.loc[i, 'Signal'] = 'Hold' df.loc[i, 'Market'] = 1 或者(更喜欢这个,超过上面一个) for i in df.index.values: if df.loc[i, 'Average_Diff'] == int(2): d ...
-
您可以MultiIndex楼层除法和模数在列中创建MultiIndex ,然后使用stack ,删除index第一级MultiIndex add reset_index : k = [1,2,3,4,5,6,7,8,9,10,11,12] k = pd.DataFrame(k).T k.columns = [k.columns // 4, k.columns % 4] print (k) 0 1 2 0 1 2 3 0 ...
-
threeyrs = pd.concat([actdf['01/01/2009':'12/01/2009'], actdf['01/01/2011':'12/01/2012']]) threeyrs = pd.concat([actdf['01/01/2009':'12/01/2009'], actdf['01/01/2011':'12/01/2012']])
-
你用一个香草Python列表覆盖了你的DF: df = [['Adj. Open','Adj. High','Adj. Low','Adj. Close','Adj. Volume']] 试试这个: In [102]: df = df.filter(regex='^Adj\.') In [103]: df Out[103]: Adj. Open Adj. High Adj. Low Adj. Close Adj. Volume Date 2004-08-19 ...
-
Pandas Dataframe选择多个不连续的列/切片(Pandas Dataframe select multiple discontinuous columns/slices)[2022-05-29]
将np.r_ indexer与iloc结合使用,如下所示: df.iloc[:, np.r_[0:32, 83]] np.r_[0:32, 83] array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 83]) Use the np.r_ indexer in conjunc ... -
无需迭代,您可以直接应用list : df.groupby('Col_A')['Col_B'].apply(list) 确保选择'Col_B'以应用系列list ,否则list将返回数据框的列。 编辑 您可以存储原始(第一个)索引,如下所示: original_index = df.reset_index(drop=False).groupby('Col_A')['Index'].first() 然后将原始索引与前一个结果合并: result = df.groupby('Col_A')['Col_B'] ...
-
堆叠和整形DataFrame(pandas)切片而不循环(Stacking and shaping slices of DataFrame (pandas) without looping)[2024-01-19]
它不一定是最漂亮的,但在过去我做过类似的事情 df = pd.read_csv("vd.csv", sep="\s+") d2 = pd.melt(df, id_vars="day") d2["sample"] = d2.groupby(["variable", "day"])["day"].rank("first") d3 = d2.pivot_table(index=["variable", "sample"], columns="day") 这使 >>> d3 ... -
我想你需要melt : df = pd.melt(df, id_vars=['A','B','C'], value_name='result', var_name='date') print (df) A B C date result 0 a1 b1 c1 date1result 12 1 a2 b2 c3 date1result 5 2 a1 b1 c1 date2result 15 3 a2 b2 c3 ...
-
以这种方式定义你的功能 def fun(slices): return [df.low.loc[s].tolist() for s in slices] 并应用切片列 df['slices_low'] = df.slices.apply(fun) df define your function this way def fun(slices): return [df.low.loc[s].tolist() for s in slices] And apply over the sli ...