The following issues were found
pandas/io/date_converters.py
8 issues
Line: 6
Column: 1
import numpy as np
from pandas._libs.tslibs import parsing
def parse_date_time(date_col, time_col):
"""
Parse columns with dates and times into a single datetime column.
Reported by Pylint.
Line: 36
Column: 1
"""
warnings.warn(
"""
Use pd.to_datetime({"year": year_col, "month": month_col, "day": day_col}) instead to get a Pandas Series.
Use ser = pd.to_datetime({"year": year_col, "month": month_col, "day": day_col}) and
np.array([s.to_pydatetime() for s in ser]) instead to get a Numpy array.
""", # noqa: E501
FutureWarning,
stacklevel=2,
Reported by Pylint.
Line: 50
Column: 1
return parsing.try_parse_year_month_day(year_col, month_col, day_col)
def parse_all_fields(year_col, month_col, day_col, hour_col, minute_col, second_col):
"""
Parse columns with datetime information into a single datetime column.
.. deprecated:: 1.2
"""
Reported by Pylint.
Line: 60
Column: 1
warnings.warn(
"""
Use pd.to_datetime({"year": year_col, "month": month_col, "day": day_col,
"hour": hour_col, "minute": minute_col, second": second_col}) instead to get a Pandas Series.
Use ser = pd.to_datetime({"year": year_col, "month": month_col, "day": day_col,
"hour": hour_col, "minute": minute_col, second": second_col}) and
np.array([s.to_pydatetime() for s in ser]) instead to get a Numpy array.
""", # noqa: E501
FutureWarning,
Reported by Pylint.
Line: 95
Column: 5
stacklevel=2,
)
N = _check_columns(cols)
results = np.empty(N, dtype=object)
for i in range(N):
args = [c[i] for c in cols]
results[i] = parse_func(*args)
Reported by Pylint.
Line: 112
Column: 8
def _check_columns(cols):
if not len(cols):
raise AssertionError("There must be at least 1 column")
head, tail = cols[0], cols[1:]
N = len(head)
Reported by Pylint.
Line: 117
Column: 5
head, tail = cols[0], cols[1:]
N = len(head)
for i, n in enumerate(map(len, tail)):
if n != N:
raise AssertionError(
f"All columns must have the same length: {N}; column {i} has length {n}"
Reported by Pylint.
Line: 119
Column: 12
N = len(head)
for i, n in enumerate(map(len, tail)):
if n != N:
raise AssertionError(
f"All columns must have the same length: {N}; column {i} has length {n}"
)
Reported by Pylint.
pandas/core/window/online.py
8 issues
Line: 1
Column: 1
from typing import (
Dict,
Optional,
)
import numpy as np
from pandas.compat._optional import import_optional_dependency
Reported by Pylint.
Line: 37
Column: 5
numba = import_optional_dependency("numba")
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
def online_ewma(
values: np.ndarray,
deltas: np.ndarray,
minimum_periods: int,
old_wt_factor: float,
new_wt: float,
Reported by Pylint.
Line: 58
Column: 9
nobs = (~np.isnan(weighted_avg)).astype(np.int64)
result[0] = np.where(nobs >= minimum_periods, weighted_avg, np.nan)
for i in range(1, len(values)):
cur = values[i]
is_observations = ~np.isnan(cur)
nobs += is_observations.astype(np.int64)
for j in numba.prange(len(cur)):
if not np.isnan(weighted_avg[j]):
Reported by Pylint.
Line: 89
Column: 1
return online_ewma
class EWMMeanState:
def __init__(self, com, adjust, ignore_na, axis, shape):
alpha = 1.0 / (1.0 + com)
self.axis = axis
self.shape = shape
self.adjust = adjust
Reported by Pylint.
Line: 89
Column: 1
return online_ewma
class EWMMeanState:
def __init__(self, com, adjust, ignore_na, axis, shape):
alpha = 1.0 / (1.0 + com)
self.axis = axis
self.shape = shape
self.adjust = adjust
Reported by Pylint.
Line: 90
Column: 5
class EWMMeanState:
def __init__(self, com, adjust, ignore_na, axis, shape):
alpha = 1.0 / (1.0 + com)
self.axis = axis
self.shape = shape
self.adjust = adjust
self.ignore_na = ignore_na
Reported by Pylint.
Line: 101
Column: 5
self.old_wt = np.ones(self.shape[self.axis - 1])
self.last_ewm = None
def run_ewm(self, weighted_avg, deltas, min_periods, ewm_func):
result, old_wt = ewm_func(
weighted_avg,
deltas,
min_periods,
self.old_wt_factor,
Reported by Pylint.
Line: 116
Column: 5
self.last_ewm = result[-1]
return result
def reset(self):
self.old_wt = np.ones(self.shape[self.axis - 1])
self.last_ewm = None
Reported by Pylint.
pandas/tests/frame/test_validate.py
7 issues
Line: 1
Column: 1
import pytest
from pandas.core.frame import DataFrame
@pytest.fixture
def dataframe():
return DataFrame({"a": [1, 2], "b": [3, 4]})
Reported by Pylint.
Line: 27
Column: 39
],
)
@pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0])
def test_validate_bool_args(self, dataframe, func, inplace):
msg = 'For argument "inplace" expected type bool'
kwargs = {"inplace": inplace}
if func == "query":
kwargs["expr"] = "a > b"
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas.core.frame import DataFrame
@pytest.fixture
def dataframe():
return DataFrame({"a": [1, 2], "b": [3, 4]})
Reported by Pylint.
Line: 7
Column: 1
@pytest.fixture
def dataframe():
return DataFrame({"a": [1, 2], "b": [3, 4]})
class TestDataFrameValidate:
"""Tests for error handling related to data types of method arguments."""
Reported by Pylint.
Line: 11
Column: 1
return DataFrame({"a": [1, 2], "b": [3, 4]})
class TestDataFrameValidate:
"""Tests for error handling related to data types of method arguments."""
@pytest.mark.parametrize(
"func",
[
Reported by Pylint.
Line: 25
Column: 5
"drop_duplicates",
"sort_values",
],
)
@pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0])
def test_validate_bool_args(self, dataframe, func, inplace):
msg = 'For argument "inplace" expected type bool'
kwargs = {"inplace": inplace}
Reported by Pylint.
Line: 25
Column: 5
"drop_duplicates",
"sort_values",
],
)
@pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0])
def test_validate_bool_args(self, dataframe, func, inplace):
msg = 'For argument "inplace" expected type bool'
kwargs = {"inplace": inplace}
Reported by Pylint.
pandas/io/feather_format.py
7 issues
Line: 46
Column: 5
.. versionadded:: 1.1.0
"""
import_optional_dependency("pyarrow")
from pyarrow import feather
if not isinstance(df, DataFrame):
raise ValueError("feather only support IO with DataFrames")
valid_types = {"string", "unicode"}
Reported by Pylint.
Line: 124
Column: 5
type of object stored in file
"""
import_optional_dependency("pyarrow")
from pyarrow import feather
with get_handle(
path, "rb", storage_options=storage_options, is_text=False
) as handles:
Reported by Pylint.
Line: 22
Column: 22
from pandas.io.common import get_handle
@doc(storage_options=generic._shared_docs["storage_options"])
def to_feather(
df: DataFrame,
path: FilePathOrBuffer[AnyStr],
storage_options: StorageOptions = None,
**kwargs,
Reported by Pylint.
Line: 90
Column: 22
feather.write_feather(df, handles.handle, **kwargs)
@doc(storage_options=generic._shared_docs["storage_options"])
def read_feather(
path, columns=None, use_threads: bool = True, storage_options: StorageOptions = None
):
"""
Load a feather-format object from the file path.
Reported by Pylint.
Line: 23
Column: 1
@doc(storage_options=generic._shared_docs["storage_options"])
def to_feather(
df: DataFrame,
path: FilePathOrBuffer[AnyStr],
storage_options: StorageOptions = None,
**kwargs,
):
Reported by Pylint.
Line: 46
Column: 5
.. versionadded:: 1.1.0
"""
import_optional_dependency("pyarrow")
from pyarrow import feather
if not isinstance(df, DataFrame):
raise ValueError("feather only support IO with DataFrames")
valid_types = {"string", "unicode"}
Reported by Pylint.
Line: 124
Column: 5
type of object stored in file
"""
import_optional_dependency("pyarrow")
from pyarrow import feather
with get_handle(
path, "rb", storage_options=storage_options, is_text=False
) as handles:
Reported by Pylint.
pandas/_libs/src/ujson/lib/ultrajsonenc.c
7 issues
Line: 827
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
#else
snprintf(precision_str + 2, sizeof(precision_str) - 2, "%ug",
enc->doublePrecision);
enc->offset += snprintf(str, enc->end - enc->offset, precision_str,
neg ? -value : value);
#endif
return TRUE;
}
Reported by FlawFinder.
Line: 390
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
SetError(NULL, enc, "Could not reserve memory block");
return;
}
memcpy(enc->start, oldStart, offset);
}
enc->offset = enc->start + offset;
enc->end = enc->start + newSize;
}
Reported by FlawFinder.
Line: 553
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
return FALSE;
}
memcpy(&in16, io, sizeof(JSUTF16));
in = (JSUTF32)in16;
#ifdef __LITTLE_ENDIAN__
ucs = ((in & 0x1f) << 6) | ((in >> 8) & 0x3f);
#else
Reported by FlawFinder.
Line: 587
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
return FALSE;
}
memcpy(&in16, io, sizeof(JSUTF16));
memcpy(&in8, io + 2, sizeof(JSUINT8));
#ifdef __LITTLE_ENDIAN__
in = (JSUTF32)in16;
in |= in8 << 16;
ucs = ((in & 0x0f) << 12) | ((in & 0x3f00) >> 2) |
Reported by FlawFinder.
Line: 588
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
memcpy(&in16, io, sizeof(JSUTF16));
memcpy(&in8, io + 2, sizeof(JSUINT8));
#ifdef __LITTLE_ENDIAN__
in = (JSUTF32)in16;
in |= in8 << 16;
ucs = ((in & 0x0f) << 12) | ((in & 0x3f00) >> 2) |
((in & 0x3f0000) >> 16);
Reported by FlawFinder.
Line: 623
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
return FALSE;
}
memcpy(&in, io, sizeof(JSUTF32));
#ifdef __LITTLE_ENDIAN__
ucs = ((in & 0x07) << 18) | ((in & 0x3f00) << 4) |
((in & 0x3f0000) >> 10) | ((in & 0x3f000000) >> 24);
#else
ucs = ((in & 0x07000000) >> 6) | ((in & 0x3f0000) >> 4) |
Reported by FlawFinder.
Line: 784
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
/* if input is beyond the thresholds, revert to exponential */
const double thres_max = (double)1e16 - 1;
const double thres_min = (double)1e-15;
char precision_str[20];
int count;
double diff = 0.0;
char *str = enc->offset;
char *wstr = str;
unsigned long long whole;
Reported by FlawFinder.
ci/print_skipped.py
7 issues
Line: 10
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-elementtree
if not os.path.isfile(filename):
raise RuntimeError(f"Could not find junit file {repr(filename)}")
tree = et.parse(filename)
root = tree.getroot()
current_class = ""
for el in root.iter("testcase"):
cn = el.attrib["classname"]
for sk in el.findall("skipped"):
Reported by Bandit.
Line: 1
Column: 1
#!/usr/bin/env python3
import os
import xml.etree.ElementTree as et
def main(filename):
if not os.path.isfile(filename):
raise RuntimeError(f"Could not find junit file {repr(filename)}")
Reported by Pylint.
Line: 3
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b405-import-xml-etree
#!/usr/bin/env python3
import os
import xml.etree.ElementTree as et
def main(filename):
if not os.path.isfile(filename):
raise RuntimeError(f"Could not find junit file {repr(filename)}")
Reported by Bandit.
Line: 6
Column: 1
import xml.etree.ElementTree as et
def main(filename):
if not os.path.isfile(filename):
raise RuntimeError(f"Could not find junit file {repr(filename)}")
tree = et.parse(filename)
root = tree.getroot()
Reported by Pylint.
Line: 13
Column: 9
tree = et.parse(filename)
root = tree.getroot()
current_class = ""
for el in root.iter("testcase"):
cn = el.attrib["classname"]
for sk in el.findall("skipped"):
old_class = current_class
current_class = cn
if old_class != current_class:
Reported by Pylint.
Line: 14
Column: 9
root = tree.getroot()
current_class = ""
for el in root.iter("testcase"):
cn = el.attrib["classname"]
for sk in el.findall("skipped"):
old_class = current_class
current_class = cn
if old_class != current_class:
yield None
Reported by Pylint.
Line: 15
Column: 13
current_class = ""
for el in root.iter("testcase"):
cn = el.attrib["classname"]
for sk in el.findall("skipped"):
old_class = current_class
current_class = cn
if old_class != current_class:
yield None
yield {
Reported by Pylint.
pandas/tests/extension/base/io.py
7 issues
Line: 4
Column: 1
from io import StringIO
import numpy as np
import pytest
import pandas as pd
from pandas.tests.extension.base.base import BaseExtensionTests
Reported by Pylint.
Line: 1
Column: 1
from io import StringIO
import numpy as np
import pytest
import pandas as pd
from pandas.tests.extension.base.base import BaseExtensionTests
Reported by Pylint.
Line: 1
Column: 1
from io import StringIO
import numpy as np
import pytest
import pandas as pd
from pandas.tests.extension.base.base import BaseExtensionTests
Reported by Pylint.
Line: 10
Column: 1
from pandas.tests.extension.base.base import BaseExtensionTests
class BaseParsingTests(BaseExtensionTests):
@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
df = pd.DataFrame({"with_dtype": pd.Series(data, dtype=str(data.dtype))})
csv_output = df.to_csv(index=False, na_rep=np.nan)
result = pd.read_csv(
Reported by Pylint.
Line: 12
Column: 5
class BaseParsingTests(BaseExtensionTests):
@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
df = pd.DataFrame({"with_dtype": pd.Series(data, dtype=str(data.dtype))})
csv_output = df.to_csv(index=False, na_rep=np.nan)
result = pd.read_csv(
StringIO(csv_output), dtype={"with_dtype": str(data.dtype)}, engine=engine
)
Reported by Pylint.
Line: 12
Column: 5
class BaseParsingTests(BaseExtensionTests):
@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
df = pd.DataFrame({"with_dtype": pd.Series(data, dtype=str(data.dtype))})
csv_output = df.to_csv(index=False, na_rep=np.nan)
result = pd.read_csv(
StringIO(csv_output), dtype={"with_dtype": str(data.dtype)}, engine=engine
)
Reported by Pylint.
Line: 13
Column: 9
class BaseParsingTests(BaseExtensionTests):
@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
df = pd.DataFrame({"with_dtype": pd.Series(data, dtype=str(data.dtype))})
csv_output = df.to_csv(index=False, na_rep=np.nan)
result = pd.read_csv(
StringIO(csv_output), dtype={"with_dtype": str(data.dtype)}, engine=engine
)
expected = df
Reported by Pylint.
pandas/tests/indexes/datetimes/test_asof.py
7 issues
Line: 1
Column: 1
from pandas import (
Index,
Timestamp,
date_range,
)
class TestAsOf:
def test_asof_partial(self):
Reported by Pylint.
Line: 8
Column: 1
)
class TestAsOf:
def test_asof_partial(self):
index = date_range("2010-01-01", periods=2, freq="m")
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
Reported by Pylint.
Line: 8
Column: 1
)
class TestAsOf:
def test_asof_partial(self):
index = date_range("2010-01-01", periods=2, freq="m")
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
Reported by Pylint.
Line: 9
Column: 5
class TestAsOf:
def test_asof_partial(self):
index = date_range("2010-01-01", periods=2, freq="m")
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
assert not isinstance(result, Index)
Reported by Pylint.
Line: 9
Column: 5
class TestAsOf:
def test_asof_partial(self):
index = date_range("2010-01-01", periods=2, freq="m")
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
assert not isinstance(result, Index)
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
index = date_range("2010-01-01", periods=2, freq="m")
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
assert not isinstance(result, Index)
Reported by Bandit.
Line: 14
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
assert not isinstance(result, Index)
Reported by Bandit.
pandas/tests/extension/conftest.py
7 issues
Line: 3
Column: 1
import operator
import pytest
from pandas import Series
@pytest.fixture
def dtype():
Reported by Pylint.
Line: 38
Column: 29
@pytest.fixture(params=["data", "data_missing"])
def all_data(request, data, data_missing):
"""Parametrized fixture giving 'data' and 'data_missing'"""
if request.param == "data":
return data
elif request.param == "data_missing":
return data_missing
Reported by Pylint.
Line: 38
Column: 23
@pytest.fixture(params=["data", "data_missing"])
def all_data(request, data, data_missing):
"""Parametrized fixture giving 'data' and 'data_missing'"""
if request.param == "data":
return data
elif request.param == "data_missing":
return data_missing
Reported by Pylint.
Line: 47
Column: 19
@pytest.fixture
def data_repeated(data):
"""
Generate many datasets.
Parameters
----------
Reported by Pylint.
Line: 1
Column: 1
import operator
import pytest
from pandas import Series
@pytest.fixture
def dtype():
Reported by Pylint.
Line: 38
Column: 1
@pytest.fixture(params=["data", "data_missing"])
def all_data(request, data, data_missing):
"""Parametrized fixture giving 'data' and 'data_missing'"""
if request.param == "data":
return data
elif request.param == "data_missing":
return data_missing
Reported by Pylint.
Line: 40
Column: 5
@pytest.fixture(params=["data", "data_missing"])
def all_data(request, data, data_missing):
"""Parametrized fixture giving 'data' and 'data_missing'"""
if request.param == "data":
return data
elif request.param == "data_missing":
return data_missing
Reported by Pylint.
pandas/core/window/numba_.py
7 issues
Line: 290
Column: 9
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
def ewma_table(
values: np.ndarray,
begin: np.ndarray,
end: np.ndarray,
minimum_periods: int,
) -> np.ndarray:
alpha = 1.0 / (1.0 + com)
old_wt_factor = 1.0 - alpha
Reported by Pylint.
Line: 291
Column: 9
def ewma_table(
values: np.ndarray,
begin: np.ndarray,
end: np.ndarray,
minimum_periods: int,
) -> np.ndarray:
alpha = 1.0 / (1.0 + com)
old_wt_factor = 1.0 - alpha
new_wt = 1.0 if adjust else alpha
Reported by Pylint.
Line: 1
Column: 1
from __future__ import annotations
import functools
from typing import (
Any,
Callable,
)
import numpy as np
Reported by Pylint.
Line: 116
Column: 5
numba = import_optional_dependency("numba")
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
def ewma(
values: np.ndarray,
begin: np.ndarray,
end: np.ndarray,
minimum_periods: int,
) -> np.ndarray:
Reported by Pylint.
Line: 127
Column: 9
old_wt_factor = 1.0 - alpha
new_wt = 1.0 if adjust else alpha
for i in numba.prange(len(begin)):
start = begin[i]
stop = end[i]
window = values[start:stop]
sub_result = np.empty(len(window))
Reported by Pylint.
Line: 241
Column: 1
# axis for all np.nan* agg functions
# https://github.com/numba/numba/issues/1269
@functools.lru_cache(maxsize=None)
def generate_manual_numpy_nan_agg_with_axis(nan_func):
numba = import_optional_dependency("numba")
@numba.jit(nopython=True, nogil=True, parallel=True)
def nan_agg_with_axis(table):
result = np.empty(table.shape[1])
Reported by Pylint.
Line: 303
Column: 9
weighted_avg = values[0].copy()
nobs = (~np.isnan(weighted_avg)).astype(np.int64)
result[0] = np.where(nobs >= minimum_periods, weighted_avg, np.nan)
for i in range(1, len(values)):
cur = values[i]
is_observations = ~np.isnan(cur)
nobs += is_observations.astype(np.int64)
for j in numba.prange(len(cur)):
if not np.isnan(weighted_avg[j]):
Reported by Pylint.