Skip to content

Commit 8995793

Browse files
author
MomIsBestFriend
committed
Merge remote-tracking branch 'upstream/master' into CI-TestCase-#29886
2 parents 816d5c2 + a9e2566 commit 8995793

File tree

5 files changed

+31
-35
lines changed

5 files changed

+31
-35
lines changed

pandas/_libs/parsers.pyx

+20-1
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,26 @@ def _ensure_encoded(list lst):
13671367
# common NA values
13681368
# no longer excluding inf representations
13691369
# '1.#INF','-1.#INF', '1.#INF000000',
1370-
_NA_VALUES = _ensure_encoded(list(icom._NA_VALUES))
1370+
STR_NA_VALUES = {
1371+
"-1.#IND",
1372+
"1.#QNAN",
1373+
"1.#IND",
1374+
"-1.#QNAN",
1375+
"#N/A N/A",
1376+
"#N/A",
1377+
"N/A",
1378+
"n/a",
1379+
"NA",
1380+
"#NA",
1381+
"NULL",
1382+
"null",
1383+
"NaN",
1384+
"-NaN",
1385+
"nan",
1386+
"-nan",
1387+
"",
1388+
}
1389+
_NA_VALUES = _ensure_encoded(list(STR_NA_VALUES))
13711390

13721391

13731392
def _maybe_upcast(arr):

pandas/io/common.py

-23
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,6 @@
4747

4848
lzma = _import_lzma()
4949

50-
# common NA values
51-
# no longer excluding inf representations
52-
# '1.#INF','-1.#INF', '1.#INF000000',
53-
_NA_VALUES = {
54-
"-1.#IND",
55-
"1.#QNAN",
56-
"1.#IND",
57-
"-1.#QNAN",
58-
"#N/A N/A",
59-
"#N/A",
60-
"N/A",
61-
"n/a",
62-
"NA",
63-
"#NA",
64-
"NULL",
65-
"null",
66-
"NaN",
67-
"-NaN",
68-
"nan",
69-
"-nan",
70-
"",
71-
}
72-
7350

7451
_VALID_URLS = set(uses_relative + uses_netloc + uses_params)
7552
_VALID_URLS.discard("")

pandas/io/excel/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from pandas._config import config
88

9+
from pandas._libs.parsers import STR_NA_VALUES
910
from pandas.errors import EmptyDataError
1011
from pandas.util._decorators import Appender
1112

@@ -14,7 +15,6 @@
1415
from pandas.core.frame import DataFrame
1516

1617
from pandas.io.common import (
17-
_NA_VALUES,
1818
_is_url,
1919
_stringify_path,
2020
_validate_header_arg,
@@ -124,7 +124,7 @@
124124
Additional strings to recognize as NA/NaN. If dict passed, specific
125125
per-column NA values. By default the following values are interpreted
126126
as NaN: '"""
127-
+ fill("', '".join(sorted(_NA_VALUES)), 70, subsequent_indent=" ")
127+
+ fill("', '".join(sorted(STR_NA_VALUES)), 70, subsequent_indent=" ")
128128
+ """'.
129129
keep_default_na : bool, default True
130130
Whether or not to include the default NaN values when parsing the data.

pandas/io/parsers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import pandas._libs.lib as lib
1818
import pandas._libs.ops as libops
1919
import pandas._libs.parsers as parsers
20+
from pandas._libs.parsers import STR_NA_VALUES
2021
from pandas._libs.tslibs import parsing
2122
from pandas.errors import (
2223
AbstractMethodError,
@@ -60,7 +61,6 @@
6061
from pandas.core.tools import datetimes as tools
6162

6263
from pandas.io.common import (
63-
_NA_VALUES,
6464
BaseIterator,
6565
UnicodeReader,
6666
UTF8Recoder,
@@ -195,7 +195,7 @@
195195
Additional strings to recognize as NA/NaN. If dict passed, specific
196196
per-column NA values. By default the following values are interpreted as
197197
NaN: '"""
198-
+ fill("', '".join(sorted(_NA_VALUES)), 70, subsequent_indent=" ")
198+
+ fill("', '".join(sorted(STR_NA_VALUES)), 70, subsequent_indent=" ")
199199
+ """'.
200200
keep_default_na : bool, default True
201201
Whether or not to include the default NaN values when parsing the data.
@@ -3398,7 +3398,7 @@ def _clean_na_values(na_values, keep_default_na=True):
33983398

33993399
if na_values is None:
34003400
if keep_default_na:
3401-
na_values = _NA_VALUES
3401+
na_values = STR_NA_VALUES
34023402
else:
34033403
na_values = set()
34043404
na_fvalues = set()
@@ -3415,7 +3415,7 @@ def _clean_na_values(na_values, keep_default_na=True):
34153415
v = [v]
34163416

34173417
if keep_default_na:
3418-
v = set(v) | _NA_VALUES
3418+
v = set(v) | STR_NA_VALUES
34193419

34203420
na_values[k] = v
34213421
na_fvalues = {k: _floatify_na_values(v) for k, v in na_values.items()}
@@ -3424,7 +3424,7 @@ def _clean_na_values(na_values, keep_default_na=True):
34243424
na_values = [na_values]
34253425
na_values = _stringify_na_values(na_values)
34263426
if keep_default_na:
3427-
na_values = na_values | _NA_VALUES
3427+
na_values = na_values | STR_NA_VALUES
34283428

34293429
na_fvalues = _floatify_na_values(na_values)
34303430

@@ -3575,7 +3575,7 @@ def _get_na_values(col, na_values, na_fvalues, keep_default_na):
35753575
return na_values[col], na_fvalues[col]
35763576
else:
35773577
if keep_default_na:
3578-
return _NA_VALUES, set()
3578+
return STR_NA_VALUES, set()
35793579

35803580
return set(), set()
35813581
else:

pandas/tests/io/parser/test_na_values.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import numpy as np
88
import pytest
99

10+
from pandas._libs.parsers import STR_NA_VALUES
11+
1012
from pandas import DataFrame, Index, MultiIndex
1113
import pandas.util.testing as tm
1214

13-
import pandas.io.common as com
14-
1515

1616
def test_string_nas(all_parsers):
1717
parser = all_parsers
@@ -99,7 +99,7 @@ def test_default_na_values(all_parsers):
9999
"#N/A N/A",
100100
"",
101101
}
102-
assert _NA_VALUES == com._NA_VALUES
102+
assert _NA_VALUES == STR_NA_VALUES
103103

104104
parser = all_parsers
105105
nv = len(_NA_VALUES)

0 commit comments

Comments
 (0)