<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;&quot;&quot;Pandas bug.&quot;&quot;&quot;
from numpy.random import choice, seed
from pandas import DataFrame
from pandas.util.testing import rands_array

seed(1234)
N = 5 * 10 ** 6

DTF = DataFrame({'Col{}'.format(k): choice(rands_array(10, 750), N) for k in range(65)})

print(DTF)

DTF.to_csv('File{}.csv'.format(N)"><pre class="notranslate"><span class="pl-s">"""Pandas bug."""</span>
<span class="pl-k">from</span> <span class="pl-s1">numpy</span>.<span class="pl-s1">random</span> <span class="pl-k">import</span> <span class="pl-s1">choice</span>, <span class="pl-s1">seed</span>
<span class="pl-k">from</span> <span class="pl-s1">pandas</span> <span class="pl-k">import</span> <span class="pl-v">DataFrame</span>
<span class="pl-k">from</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">util</span>.<span class="pl-s1">testing</span> <span class="pl-k">import</span> <span class="pl-s1">rands_array</span>

<span class="pl-en">seed</span>(<span class="pl-c1">1234</span>)
<span class="pl-v">N</span> <span class="pl-c1">=</span> <span class="pl-c1">5</span> <span class="pl-c1">*</span> <span class="pl-c1">10</span> <span class="pl-c1">**</span> <span class="pl-c1">6</span>

<span class="pl-v">DTF</span> <span class="pl-c1">=</span> <span class="pl-v">DataFrame</span>({<span class="pl-s">'Col{}'</span>.<span class="pl-en">format</span>(<span class="pl-s1">k</span>): <span class="pl-en">choice</span>(<span class="pl-en">rands_array</span>(<span class="pl-c1">10</span>, <span class="pl-c1">750</span>), <span class="pl-v">N</span>) <span class="pl-k">for</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">65</span>)})

<span class="pl-en">print</span>(<span class="pl-v">DTF</span>)

<span class="pl-v">DTF</span>.<span class="pl-s1">to_csv</span>(<span class="pl-s">'File{}.csv'</span>.<span class="pl-en">format</span>(<span class="pl-v">N</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">to_csv exception, eventually linked to latest version regression <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="332207625" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/21471" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/21471/hovercard" href="https://github.com/pandas-dev/pandas/issues/21471">#21471</a> issue with to_csv with compression</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Expected no exception</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py&quot;, line 1745, in to_csv
    formatter.save()
  File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/formats/csvs.py&quot;, line 166, in save
    f.write(buf)
OSError: [Errno 22] Invalid argument"><pre class="notranslate">  File <span class="pl-s"><span class="pl-pds">"</span>/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py<span class="pl-pds">"</span></span>, line 1745, <span class="pl-k">in</span> to_csv
    <span class="pl-en">formatter.save</span>()
  File <span class="pl-s"><span class="pl-pds">"</span>/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/formats/csvs.py<span class="pl-pds">"</span></span>, line 166, <span class="pl-k">in</span> save
    f.write(buf)
OSError: [Errno 22] Invalid argument</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.5.final.0<br>
python-bits: 64<br>
OS: Darwin<br>
OS-release: 17.6.0<br>
machine: x86_64<br>
processor: i386<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_US.UTF-8<br>
LOCALE: en_US.UTF-8</p>
<p dir="auto">pandas: 0.23.1<br>
pytest: None<br>
pip: 10.0.1<br>
setuptools: 39.0.1<br>
Cython: None<br>
numpy: 1.14.5<br>
scipy: 1.1.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: None<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.7.3<br>
pytz: 2018.4<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: 1.1.0<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">xref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="139848261" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/12585" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/12585/hovercard" href="https://github.com/pandas-dev/pandas/issues/12585">#12585</a></p>
<p dir="auto">I think this ought to raise a ValueErrror:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: pd.to_datetime('01-13-2012', dayfirst=True)
Out[1]: datetime.datetime(2012, 1, 13, 0, 0)"><pre class="notranslate"><code class="notranslate">In [1]: pd.to_datetime('01-13-2012', dayfirst=True)
Out[1]: datetime.datetime(2012, 1, 13, 0, 0)
</code></pre></div>
<p dir="auto"><em>This means if my data is bad (i.e. somehow I have a mixture of american and british string-dates), I won't be told there was an issue when parsing! I can't think of a usecase where this kind of precedence would be appropriate, and it means you'll end up with incorrect dates.</em></p>
<p dir="auto">The <a href="http://labix.org/python-dateutil#head-b95ce2094d189a89f80f5ae52a05b4ab7b41af47" rel="nofollow">precedence behaviour</a> appears to be a feature from <code class="notranslate">dateutil</code> (which <code class="notranslate">tslib.array_to_datetime</code> calls):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [2]: from dateutil.parser import parse as parse_date

In [3]: parse_date('1/12/2012', dayfirst=True)
Out[3]: datetime.datetime(2012, 12, 1, 0, 0)

In [4]: parse_date('1/13/2012', dayfirst=True)
Out[4]: datetime.datetime(2012, 1, 13, 0, 0)"><pre class="notranslate"><code class="notranslate">In [2]: from dateutil.parser import parse as parse_date

In [3]: parse_date('1/12/2012', dayfirst=True)
Out[3]: datetime.datetime(2012, 12, 1, 0, 0)

In [4]: parse_date('1/13/2012', dayfirst=True)
Out[4]: datetime.datetime(2012, 1, 13, 0, 0)
</code></pre></div>
<p dir="auto">It should raising like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [5]: parse_date('14/14/2012', dayfirst=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-5-ca14fc16e421&gt; in &lt;module&gt;()
----&gt; 1 parse_date('14/14/2012', dayfirst=True)

/Library/Python/2.7/site-packages/dateutil/parser.pyc in parse(timestr, parserinfo, **kwargs)
    718         return parser(parserinfo).parse(timestr, **kwargs)
    719     else:
--&gt; 720         return DEFAULTPARSER.parse(timestr, **kwargs)
    721
    722

/Library/Python/2.7/site-packages/dateutil/parser.pyc in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
    315             if value is not None:
    316                 repl[attr] = value
--&gt; 317         ret = default.replace(**repl)
    318         if res.weekday is not None and not res.day:
    319             ret = ret+relativedelta.relativedelta(weekday=res.weekday)

ValueError: month must be in 1..12"><pre class="notranslate"><code class="notranslate">In [5]: parse_date('14/14/2012', dayfirst=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-5-ca14fc16e421&gt; in &lt;module&gt;()
----&gt; 1 parse_date('14/14/2012', dayfirst=True)

/Library/Python/2.7/site-packages/dateutil/parser.pyc in parse(timestr, parserinfo, **kwargs)
    718         return parser(parserinfo).parse(timestr, **kwargs)
    719     else:
--&gt; 720         return DEFAULTPARSER.parse(timestr, **kwargs)
    721
    722

/Library/Python/2.7/site-packages/dateutil/parser.pyc in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
    315             if value is not None:
    316                 repl[attr] = value
--&gt; 317         ret = default.replace(**repl)
    318         if res.weekday is not None and not res.day:
    319             ret = ret+relativedelta.relativedelta(weekday=res.weekday)

ValueError: month must be in 1..12
</code></pre></div>
<p dir="auto">... :(</p>