Repository: pandas-dev/pandas

Issue:
Excel parser cannot change *keep_default_na* value
The parse method in the ExcelFile class does not pass the argument _keep_default_na_ to the TextParser from pandas.io.parsers.  There is no clean way to override the default na values when parsing excel files with the current code.

My specific problem involves "NA" as a typical value for "North America" in excel files.



Discussion:

Resolving patch:
diff --git a/pandas/io/excel.py b/pandas/io/excel.py
--- a/pandas/io/excel.py
+++ b/pandas/io/excel.py
@@ -126,7 +126,8 @@ def parse(self, sheetname, header=0, skiprows=None, skip_footer=0,
                                      na_values=na_values,
                                      thousands=thousands,
                                      chunksize=chunksize,
-                                     skip_footer=skip_footer)
+                                     skip_footer=skip_footer,
+                                     **kwds)
 
     def _should_parse(self, i, parse_cols):
 
@@ -163,7 +164,8 @@ def _excel2num(x):
     def _parse_excel(self, sheetname, header=0, skiprows=None,
                    skip_footer=0, index_col=None, has_index_names=None,
                    parse_cols=None, parse_dates=False, date_parser=None,
-                   na_values=None, thousands=None, chunksize=None):
+                   na_values=None, thousands=None, chunksize=None,
+                   **kwds):
         from xlrd import (xldate_as_tuple, XL_CELL_DATE,
                           XL_CELL_ERROR, XL_CELL_BOOLEAN)
 
@@ -206,7 +208,8 @@ def _parse_excel(self, sheetname, header=0, skiprows=None,
                             date_parser=date_parser,
                             skiprows=skiprows,
                             skip_footer=skip_footer,
-                            chunksize=chunksize)
+                            chunksize=chunksize,
+                            **kwds)
 
         return parser.read()
 


Test patch:
diff --git a/pandas/io/tests/data/test2.xlsx b/pandas/io/tests/data/test2.xlsx
new file mode 100644
Binary files /dev/null and b/pandas/io/tests/data/test2.xlsx differ
diff --git a/pandas/io/tests/test_excel.py b/pandas/io/tests/test_excel.py
--- a/pandas/io/tests/test_excel.py
+++ b/pandas/io/tests/test_excel.py
@@ -182,6 +182,22 @@ def test_excel_cell_error_na(self):
         expected = DataFrame([[np.nan]], columns=['Test'])
         tm.assert_frame_equal(parsed, expected)
 
+    def test_excel_passes_na(self):
+        _skip_if_no_xlrd()
+
+        excel_data = ExcelFile(os.path.join(self.dirpath, 'test2.xlsx'))
+        parsed = excel_data.parse('Sheet1', keep_default_na=False,
+                                  na_values=['apple'])
+        expected = DataFrame([['NA'], [1], ['NA'], [np.nan], ['rabbit']],
+                             columns=['Test'])
+        tm.assert_frame_equal(parsed, expected)
+
+        parsed = excel_data.parse('Sheet1', keep_default_na=True,
+                                  na_values=['apple'])
+        expected = DataFrame([[np.nan], [1], [np.nan], [np.nan], ['rabbit']],
+                             columns=['Test'])
+        tm.assert_frame_equal(parsed, expected)
+
     def test_excel_table(self):
         _skip_if_no_xlrd()