Я столкнулся с проблемой, заключающейся в том, что суммирование aggfunc в pandas ведет себя не так, как ожидалось, при использовании bool[pyarrow] вместо bool.
Я столкнулся с проблемой, заключающейся в том, что суммирование aggfunc в pandas ведет себя не так, как ожидалось, при использовании bool[pyarrow] вместо bool. [code]df = pd.DataFrame({'count': [False] * 12, 'index': [0, 1] * 6, 'cols': ['a', 'b', 'c'] * 4}) # count index cols # 0 False 0 a # 1 False 1 b # 2 False 0 c # 3 False 1 a # 4 False 0 b # 5 False 1 c # 6 False 0 a # 7 False 1 b # 8 False 0 c # 9 False 1 a # 10 False 0 b # 11 False 1 c
# Returns ints # cols a b c # index # 0 0 0 0 # 1 0 0 0 df.pivot_table(values='count', aggfunc=np.sum, columns='cols', index='index') df.pivot_table(values='count', aggfunc='sum', columns='cols', index='index') df.pivot_table(values='count', aggfunc=lambda x: x.sum(), columns='cols', index='index')
# Now change to pyarrow bools df['count'] = df['count'].astype('bool[pyarrow]')
# Returns ints # cols a b c # index # 0 0 0 0 # 1 0 0 0 df.pivot_table(values='count', aggfunc=np.sum, columns='cols', index='index') df.pivot_table(values='count', aggfunc='sum', columns='cols', index='index')
# Returns a boolean # cols a b c # index # 0 False False False # 1 False False False df.pivot_table(values='count', aggfunc=lambda x: x.sum(), columns='cols', index='index') [/code] В чем причина такого поведения? Я использую pandas 2.2.0 и pyarrow 15.0.0