Table/issue 2868

This finishes up @cherti's original PR at #3055 by rebasing on master and updating to work on master.  I also fixed a few bugs and reformatted the code a bit.  After I submit this PR I'm probably going to rebase again to collapse down some of @cherti's original commits, but will still make sure they get credit.
I think that `self._format` is guaranteed to exist, at least that's the way it's supposed to work.  Maybe there is some corner where is doesn't get set and that's why the try/except was put in?  In that case `prev_format = getattr(self, '_format', None)` seems like it would work here.