TST: preserve dtypes on assignment
- [x] closes #31340 
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Couldn't find any matching tests (some tests were close but mainly based on datetime).
Have added one. Didnt look deep into the issue since its already fixed thanks @prakhar987 