BUG: windows with TemporaryFile an read_csv #13398
State: closed

- [ x] closes #13398 
- [ x] no tests added -> could not find location for IO tests?
- [ x] passes `git diff upstream/master | flake8 --diff`

Change the way of reading back to readline (consistent with the test before entering the function)

One failure on Windows 10 (Python 3.5), but expected to fail actually (should probably tag it as well?)

```
======================================================================
FAIL: test_next (pandas.io.tests.test_common.TestMMapWrapper)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "G:\Informatique\pandas\pandas\io\tests\test_common.py", line 139, in test_next   
    self.assertEqual(next_line, line)
AssertionError: 'a,b,c\r\n' != 'a,b,c\n'
- a,b,c
?      -
+ a,b,c
```


Labels:
name: Bug
name: IO CSV
description: read_csv, to_csv
name: Windows
description: Windows OS

Comments:
@mbrucher no, pls rebase on master, that test failure was fixed very recently.

I don't like skipping ANYTHING if at all possible (even on windows), yes occasionally we do, but only if its not a simple fix.

tests go here: https://github.com/pydata/pandas/blob/master/pandas/io/tests/parser/common.py

these will be testsed on all platforms and parsers. Model after other tests.s @

unless @gfyoung has a better location.

OK, thx.
Actually, I'm on master from yesterday (missed one patch, I don't know why). The test doesn't seem to be mixed on master :/

I'll add the test.

If you have something failing, pls post; its clean now on appveyor and my manual runs on 3.5 (and 2.7)

```
commit 9670b3139171b3b628cecb87a3d0b46cc0361eba
Author: Jeff Reback <jeff@reback.net>
Date:   Tue Jun 14 17:44:13 2016 -0400

    TST: skip mmap error comparison on windows

```

yeah I did end up skipping this one on windows.

@jreback : yes, `common.py` is the right place for this to go since it doesn't fall into any nice category that was laid out previously.  BTW, wouldn't consider this a bug but rather a compat issue because you can iterate over a `TemporaryFile`in Python 2.x but not in Python 3.x.

Oh... That may be because I have the anaconda version of pandas that is used instead of my develop :/
So I'll add the test and we'll see.

It may actually also fail on OS X and Linux, not only on Windows . Definitely compatibility issue, but also a mismatch in the implementation (testing the availablity of a function and using another one to do the actual work).

yeah bug/compat doesn't matter much, except what I think I overuse the compat label :<

either way if `TemporaryFile` is not behaving as 'regular' files that's an issue. More generally I would say that that is a python bug no? Or is that defined for some reason?

IOW if I have the _same_ named `TemporaryFile` is it the SAME if I close and re-open it (SAME as is name, but prob not inode, so its not the 'same')? (I am guessing no).

I've added a test. I kept read_table so that I could use a regexp with the Python engine and use the path using the generator (sep!=None or len(sep) > 1)

Indeed, files work properly. So probably a Python default in the implementation. But the test in pandas was not the good one anyway (should have tested **next** instead of readline).

## [Current coverage](https://codecov.io/gh/pydata/pandas/pull/13481?src=pr) is **84.33%**

> Merging [#13481](https://codecov.io/gh/pydata/pandas/pull/13481?src=pr) into [master](https://codecov.io/gh/pydata/pandas/branch/master?src=pr) will increase coverage by **<.01%**

``` diff
@@             master     #13481   diff @@
==========================================
  Files           138        138          
  Lines         51072      51083    +11   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43069      43083    +14   
+ Misses         8003       8000     -3   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last updated by [35bb1a1...8b52631](https://codecov.io/gh/pydata/pandas/compare/35bb1a1c2d915d862ca0daadbe1d32180a998ccf...8b52631454c9d63e8bf2f633221e54ec902a412e)

@jreback : not entirely sure why they changed the behavior of `TemporaryFile` - it's indeed an odd feature but it hasn't really reared its head until now.  With regards to your question about opening and closing again, I'm not sure I follow you here.  When you say re-open with the same name, how?  I don't think you can specify a name with `NamedTemporaryFile`.

@gfyoung No, you can't specify a name indeed. It's if you want to open the file through another mechanism (which is what people use on forums, they don't pass the object, they open the file again, but it fails for Windows if yu do this).

@mbrucher : ah, yes, that is indeed true - it fails on Windows but does work on Unix though.

ok, @gfyoung comment, and pls add a whatsnew note. ping when green.

thanks @mbrucher ping when green.

Ah, that's better!  @jreback this LGTM and is ready to merge if there are no other concerns, and Travis is happy.  Thanks for your patience @mbrucher !

Sorry for the earlier rants ;)
I fixed the last lint issues, hopefully the last commits won't break the fix I put in. We'll see tomorrow.

@jreback Everything is green now, thx for the help!

thanks!