Skip to content

REF: define NA_VALUES in libparsers #30373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,26 @@ def _ensure_encoded(list lst):
# common NA values
# no longer excluding inf representations
# '1.#INF','-1.#INF', '1.#INF000000',
_NA_VALUES = _ensure_encoded(list(icom._NA_VALUES))
STR_NA_VALUES = {
"-1.#IND",
"1.#QNAN",
"1.#IND",
"-1.#QNAN",
"#N/A N/A",
"#N/A",
"N/A",
"n/a",
"NA",
"#NA",
"NULL",
"null",
"NaN",
"-NaN",
"nan",
"-nan",
"",
}
_NA_VALUES = _ensure_encoded(list(STR_NA_VALUES))


def _maybe_upcast(arr):
Expand Down
23 changes: 0 additions & 23 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,6 @@

lzma = _import_lzma()

# common NA values
# no longer excluding inf representations
# '1.#INF','-1.#INF', '1.#INF000000',
_NA_VALUES = {
"-1.#IND",
"1.#QNAN",
"1.#IND",
"-1.#QNAN",
"#N/A N/A",
"#N/A",
"N/A",
"n/a",
"NA",
"#NA",
"NULL",
"null",
"NaN",
"-NaN",
"nan",
"-nan",
"",
}


_VALID_URLS = set(uses_relative + uses_netloc + uses_params)
_VALID_URLS.discard("")
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pandas._config import config

from pandas._libs.parsers import STR_NA_VALUES
from pandas.errors import EmptyDataError
from pandas.util._decorators import Appender

Expand All @@ -14,7 +15,6 @@
from pandas.core.frame import DataFrame

from pandas.io.common import (
_NA_VALUES,
_is_url,
_stringify_path,
_validate_header_arg,
Expand Down Expand Up @@ -124,7 +124,7 @@
Additional strings to recognize as NA/NaN. If dict passed, specific
per-column NA values. By default the following values are interpreted
as NaN: '"""
+ fill("', '".join(sorted(_NA_VALUES)), 70, subsequent_indent=" ")
+ fill("', '".join(sorted(STR_NA_VALUES)), 70, subsequent_indent=" ")
+ """'.
keep_default_na : bool, default True
Whether or not to include the default NaN values when parsing the data.
Expand Down
12 changes: 6 additions & 6 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pandas._libs.lib as lib
import pandas._libs.ops as libops
import pandas._libs.parsers as parsers
from pandas._libs.parsers import STR_NA_VALUES
from pandas._libs.tslibs import parsing
from pandas.errors import (
AbstractMethodError,
Expand Down Expand Up @@ -60,7 +61,6 @@
from pandas.core.tools import datetimes as tools

from pandas.io.common import (
_NA_VALUES,
BaseIterator,
UnicodeReader,
UTF8Recoder,
Expand Down Expand Up @@ -195,7 +195,7 @@
Additional strings to recognize as NA/NaN. If dict passed, specific
per-column NA values. By default the following values are interpreted as
NaN: '"""
+ fill("', '".join(sorted(_NA_VALUES)), 70, subsequent_indent=" ")
+ fill("', '".join(sorted(STR_NA_VALUES)), 70, subsequent_indent=" ")
+ """'.
keep_default_na : bool, default True
Whether or not to include the default NaN values when parsing the data.
Expand Down Expand Up @@ -3398,7 +3398,7 @@ def _clean_na_values(na_values, keep_default_na=True):

if na_values is None:
if keep_default_na:
na_values = _NA_VALUES
na_values = STR_NA_VALUES
else:
na_values = set()
na_fvalues = set()
Expand All @@ -3415,7 +3415,7 @@ def _clean_na_values(na_values, keep_default_na=True):
v = [v]

if keep_default_na:
v = set(v) | _NA_VALUES
v = set(v) | STR_NA_VALUES

na_values[k] = v
na_fvalues = {k: _floatify_na_values(v) for k, v in na_values.items()}
Expand All @@ -3424,7 +3424,7 @@ def _clean_na_values(na_values, keep_default_na=True):
na_values = [na_values]
na_values = _stringify_na_values(na_values)
if keep_default_na:
na_values = na_values | _NA_VALUES
na_values = na_values | STR_NA_VALUES

na_fvalues = _floatify_na_values(na_values)

Expand Down Expand Up @@ -3575,7 +3575,7 @@ def _get_na_values(col, na_values, na_fvalues, keep_default_na):
return na_values[col], na_fvalues[col]
else:
if keep_default_na:
return _NA_VALUES, set()
return STR_NA_VALUES, set()

return set(), set()
else:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/parser/test_na_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import numpy as np
import pytest

from pandas._libs.parsers import STR_NA_VALUES

from pandas import DataFrame, Index, MultiIndex
import pandas.util.testing as tm

import pandas.io.common as com


def test_string_nas(all_parsers):
parser = all_parsers
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_default_na_values(all_parsers):
"#N/A N/A",
"",
}
assert _NA_VALUES == com._NA_VALUES
assert _NA_VALUES == STR_NA_VALUES

parser = all_parsers
nv = len(_NA_VALUES)
Expand Down