Great question. My family had a pool and a smallish dog when I was younger. We had a safety fence around the pool. Our safety fence was a permanent wrought iron one, but there are also temporary ones that work for both small children and pets:
https://www.google.com/search?q=pool...h=604#imgdii=_
You can also teach your Yorkie to swim and have a ramp in the pool for escape:
Gamma Skamper Ramp Pool Ramp for Pets at PETCO