Repository: numpy/numpy
Pull request: DOC: Resolve confusion regarding hashtag in header line of csv
<!-- Please be sure you are following the instructions in the dev guidelines
http://www.numpy.org/devdocs/dev/gitwash/development_workflow.html
-->

Fix #13088 by updating the docstring of `np.genfromtxt` [here](https://github.com/numpy/numpy/blob/master/numpy/lib/npyio.py)

<!-- We'd appreciate it if your commit message is properly formatted
http://www.numpy.org/devdocs/dev/gitwash/development_workflow.html#writing-the-commit-message
-->


Problem statement:
hashtag in headerlines
<!-- Please describe the issue in detail here, and fill in the fields below -->
The following csv file should be imported by genfromtxt.
```
"Label"; "Type"; "Dim"; "#N"; "N1"; "N2"; "N3"; "N4"; "N5"; "N6"; "N7"; "N8"; "N9"; "N10"
1; TET10; 3; 10; 955; 8100; 956; 8113; 957; 8101; 8102; 8114; 8127; 958
2; TET10; 3; 10; 959; 8150; 960; 8103; 955; 8104; 8140; 8141; 8102; 958
3; TET10; 3; 10; 955; 8105; 961; 8115; 956; 8100; 8102; 8142; 8114; 958
```

### Reproducing code example:
```python
import io
import numpy as np

data_file = io.StringIO("""\
"Label"; "Type"; "Dim"; "#N"; "N1"; "N2"; "N3"; "N4"; "N5"; "N6"; "N7"; "N8"; "N9"; "N10"
1; TET10; 3; 10; 955; 8100; 956; 8113; 957; 8101; 8102; 8114; 8127; 958
2; TET10; 3; 10; 959; 8150; 960; 8103; 955; 8104; 8140; 8141; 8102; 958
3; TET10; 3; 10; 955; 8105; 961; 8115; 956; 8100; 8102; 8142; 8114; 958""")

data = np.genfromtxt(data_file, delimiter=';',names=True,
    usecols=(0,1,2,3,4,5,6,7,8,9,10,11,12,13),
    dtype="i8,S6,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8")
```

### Error message:
```
ValueError: must replace all names at once with a sequence of length 14
```

### Numpy/Python version information:
Python 3.7.2 (default, Dec 29 2018, 06:19:36) 

>>> np.__version__
'1.15.4'

Hints from issue discussion:
You can uses the `comments` argument to be something other than the default `"#"`
using `comments='%'` gets the data parsed, but the `#N` is turned into `N`
```
>>> np.genfromtxt('bug.csv',delimiter=';',names=True,usecols=\
(0,1,2,3,4,5,6,7,8,9,10,11,12,13),dtype="i8,S6,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8",\
 comments='%')
array([(1, b' TET10', 3, 10, 955, 8100, 956, 8113, 957, 8101, 8102, 8114, 8127, 958),
       (2, b' TET10', 3, 10, 959, 8150, 960, 8103, 955, 8104, 8140, 8141, 8102, 958),
       (3, b' TET10', 3, 10, 955, 8105, 961, 8115, 956, 8100, 8102, 8142, 8114, 958)],
      dtype=[('Label', '<i8'), ('Type', 'S6'), ('Dim', '<i8'), ('N', '<i8'),\
 ('N1', '<i8'), ('N2', '<i8'), ('N3', '<i8'), ('N4', '<i8'), ('N5', '<i8'), ('N6', '<i8'),\
 ('N7', '<i8'), ('N8', '<i8'), ('N9', '<i8'), ('N10', '<i8')])
```
Works fine if you override the `deletechars` argument:
```python
data = np.genfromtxt(data_file, delimiter=';',names=True,
    usecols=(0,1,2,3,4,5,6,7,8,9,10,11,12,13),
    dtype="i8,S6,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8",
    comments=None,
    deletechars='')
```
giving
```
array([(1, b' TET10', 3, 10, 955, 8100, 956, 8113, 957, 8101, 8102, 8114, 8127, 958),
       (2, b' TET10', 3, 10, 959, 8150, 960, 8103, 955, 8104, 8140, 8141, 8102, 958),
       (3, b' TET10', 3, 10, 955, 8105, 961, 8115, 956, 8100, 8102, 8142, 8114, 958)],
      dtype=[('Label', '<i8'), ('Type', 'S6'), ('Dim', '<i8'), ('#N', '<i8'), ('N1', '<i8'), ('N2', '<i8'), ('N3', '<i8'), ('N4', '<i8'), ('N5', '<i8'), ('N6', '<i8'), ('N7', '<i8'), ('N8', '<i8'), ('N9', '<i8'), ('N10', '<i8')])
```

Commit message: Clarify deletechars in docs

Patch to review:
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index ed2e26aacecb..24c857a751d7 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1572,6 +1572,9 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
         column, individually.
     comments : str, optional
         The character used to indicate the start of a comment.
+        By default, the character '#' starts a comment. If some other
+        character is used, override `deletechars` to preserve
+        special characters in the header names.
         All the characters occurring on a line after a comment are discarded
     delimiter : str, int, or sequence, optional
         The string used to separate values.  By default, any consecutive
@@ -1610,7 +1613,8 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
         for example, `file` would become `file_`.
     deletechars : str, optional
         A string combining invalid characters that must be deleted from the
-        names.
+        names. In case `comments` is something other than '#', this must be
+        an empty string in order to preserve special characters in the names.
     defaultfmt : str, optional
         A format used to define default field names, such as "f%i" or "f_%02i".
     autostrip : bool, optional


Code review comments:
diff_hunk: @@ -1610,7 +1613,8 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
         for example, `file` would become `file_`.
     deletechars : str, optional
         A string combining invalid characters that must be deleted from the
-        names.
+        names. In case `comments` is something other than '#', this must be
+        an empty string in order to preserve special characters in the names.
path: numpy/lib/npyio.py
text: @user1:
What is the default value and why does it need to be empty in the case that `#` is not the character that prefixes comments. Not saying that this is wrong, but that sounds like strange behavior, maybe a bug.

@author:
See [#13088(comment)](https://github.com/numpy/numpy/issues/13088#issuecomment-470006776), in case `#` is not the character that prefixes comments and something else is used, then `#` disappears from the header name, yes it's probably a bug, but I'm documenting it until it gets fixed at least.

diff_hunk: @@ -1572,6 +1572,9 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
         column, individually.
     comments : str, optional
         The character used to indicate the start of a comment.
+        By default, the character '#' starts a comment. If some other
+        character is used, override `deletechars` to preserve
+        special characters in the header names.
path: numpy/lib/npyio.py
text: @user1:
Could you format these lines so that they all have about the same length? Also, I don't understand the use of `deletechars` here.

@author:
Refer [#13088(comment)](https://github.com/numpy/numpy/issues/13088#issuecomment-482915623)