ENH: Add 'infer' option to compression in _get_handle()
xref #15008 
xref #17262 

Added 'infer' option to compression in `_get_handle()`.
This way for example `.to_csv()` is made more similar to `pandas.read_csv()`.
The default value remains `None `to keep backward compatibility.

- [ ] closes #xxxx
- [ ] tests passed ( 14046 passed, 1637 skipped, 11 xfailed, 1 xpassed, 7 warnings)
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

my first pull request. if there is something wrong, i'd be happy to change that.
I am not sure about the xfailed entries, I ran `pytest --skip-slow --skip-network pandas`