Python: “Too many indices for array" happens when using sparse

I want to get_dummies a dataframe, and turn the dummy columns into sparse matrix.

df = pd.DataFrame(
            {
                "A": ["a", "b", "c", "a"],
                "B": [1, 2, 3, 4]
            })
df['A'] = df['A'].astype('category')
one_hot = pd.get_dummies(df.to_sparse(), sparse=True)
print(one_hot)
one_hot.to_csv('test_sparse.csv',index=False)

one_hot:

   B  A_a  A_b  A_c
0  1    1    0    0
1  2    0    1    0
2  3    0    0    1
3  4    1    0    0

Error:

IndexError: too many indices for array

Hopefully for help!