Bear spray in the Sierra national parks is prohibited. If you are backpacking a bear canister is required in specific areas. Regardless of the area, a canister is always the easiest and most effective way to protect bears from getting your food. Check out the following link.
https://www.myyosemitepark.com/things-to-do/no-bear-spray-allowed