The following issues were found
pandas/tests/arrays/datetimes/test_constructors.py
51 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas.core.dtypes.dtypes import DatetimeTZDtype
import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import DatetimeArray
from pandas.core.arrays.datetimes import sequence_to_dt64ns
Reported by Pylint.
Line: 23
Column: 27
with pytest.raises(ValueError, match="Only 1-dimensional"):
# 3-dim, we allow 2D to sneak in for ops purposes GH#29853
DatetimeArray(arr.reshape(2, 2, 1))
with pytest.raises(ValueError, match="Only 1-dimensional"):
# 0-dim
DatetimeArray(arr[[0]].squeeze())
Reported by Pylint.
Line: 16
Column: 13
def test_from_sequence_invalid_type(self):
mi = pd.MultiIndex.from_product([np.arange(5), np.arange(5)])
with pytest.raises(TypeError, match="Cannot create a DatetimeArray"):
DatetimeArray._from_sequence(mi)
def test_only_1dim_accepted(self):
arr = np.array([0, 1, 2, 3], dtype="M8[h]").astype("M8[ns]")
with pytest.raises(ValueError, match="Only 1-dimensional"):
Reported by Pylint.
Line: 44
Column: 13
@pytest.mark.parametrize(
"meth",
[
DatetimeArray._from_sequence,
sequence_to_dt64ns,
pd.to_datetime,
pd.DatetimeIndex,
],
)
Reported by Pylint.
Line: 69
Column: 18
def test_from_pandas_array(self):
arr = pd.array(np.arange(5, dtype=np.int64)) * 3600 * 10 ** 9
result = DatetimeArray._from_sequence(arr)._with_freq("infer")
expected = pd.date_range("1970-01-01", periods=5, freq="H")._data
tm.assert_datetime_array_equal(result, expected)
def test_mismatched_timezone_raises(self):
Reported by Pylint.
Line: 69
Column: 18
def test_from_pandas_array(self):
arr = pd.array(np.arange(5, dtype=np.int64)) * 3600 * 10 ** 9
result = DatetimeArray._from_sequence(arr)._with_freq("infer")
expected = pd.date_range("1970-01-01", periods=5, freq="H")._data
tm.assert_datetime_array_equal(result, expected)
def test_mismatched_timezone_raises(self):
Reported by Pylint.
Line: 71
Column: 20
result = DatetimeArray._from_sequence(arr)._with_freq("infer")
expected = pd.date_range("1970-01-01", periods=5, freq="H")._data
tm.assert_datetime_array_equal(result, expected)
def test_mismatched_timezone_raises(self):
arr = DatetimeArray(
np.array(["2000-01-01T06:00:00"], dtype="M8[ns]"),
Reported by Pylint.
Line: 97
Column: 13
msg = r"dtype bool cannot be converted to datetime64\[ns\]"
with pytest.raises(TypeError, match=msg):
DatetimeArray._from_sequence(arr)
with pytest.raises(TypeError, match=msg):
sequence_to_dt64ns(arr)
with pytest.raises(TypeError, match=msg):
Reported by Pylint.
Line: 119
Column: 16
def test_copy(self):
data = np.array([1, 2, 3], dtype="M8[ns]")
arr = DatetimeArray(data, copy=False)
assert arr._data is data
arr = DatetimeArray(data, copy=True)
assert arr._data is not data
Reported by Pylint.
Line: 122
Column: 16
assert arr._data is data
arr = DatetimeArray(data, copy=True)
assert arr._data is not data
class TestSequenceToDT64NS:
def test_tz_dtype_mismatch_raises(self):
arr = DatetimeArray._from_sequence(
Reported by Pylint.
pandas/tests/libs/test_lib.py
51 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
writers as libwriters,
)
from pandas import Index
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
writers as libwriters,
)
from pandas import Index
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
writers as libwriters,
)
from pandas import Index
Reported by Pylint.
Line: 110
Column: 13
msg = "index 100 is out of bounds for axis (0|1) with size 100"
with pytest.raises(IndexError, match=msg):
target[indices]
with pytest.raises(IndexError, match=msg):
target[maybe_slice]
indices = np.array([100, 99, 98, 97], dtype=np.intp)
maybe_slice = lib.maybe_indices_to_slice(indices, len(target))
Reported by Pylint.
Line: 112
Column: 13
with pytest.raises(IndexError, match=msg):
target[indices]
with pytest.raises(IndexError, match=msg):
target[maybe_slice]
indices = np.array([100, 99, 98, 97], dtype=np.intp)
maybe_slice = lib.maybe_indices_to_slice(indices, len(target))
assert not isinstance(maybe_slice, slice)
Reported by Pylint.
Line: 121
Column: 13
tm.assert_numpy_array_equal(maybe_slice, indices)
with pytest.raises(IndexError, match=msg):
target[indices]
with pytest.raises(IndexError, match=msg):
target[maybe_slice]
for case in [[99, 97, 99, 96], [99, 99, 98, 97], [98, 98, 97, 96]]:
indices = np.array(case, dtype=np.intp)
Reported by Pylint.
Line: 123
Column: 13
with pytest.raises(IndexError, match=msg):
target[indices]
with pytest.raises(IndexError, match=msg):
target[maybe_slice]
for case in [[99, 97, 99, 96], [99, 99, 98, 97], [98, 98, 97, 96]]:
indices = np.array(case, dtype=np.intp)
maybe_slice = lib.maybe_indices_to_slice(indices, len(target))
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
writers as libwriters,
)
from pandas import Index
Reported by Pylint.
Line: 13
Column: 1
import pandas._testing as tm
class TestMisc:
def test_max_len_string_array(self):
arr = a = np.array(["foo", "b", np.nan], dtype="object")
assert libwriters.max_len_string_array(arr) == 3
Reported by Pylint.
Line: 14
Column: 5
class TestMisc:
def test_max_len_string_array(self):
arr = a = np.array(["foo", "b", np.nan], dtype="object")
assert libwriters.max_len_string_array(arr) == 3
# unicode
Reported by Pylint.
pandas/core/dtypes/common.py
51 issues
Line: 14
Column: 1
import numpy as np
from pandas._libs import (
Interval,
Period,
algos,
)
from pandas._libs.tslibs import conversion
Reported by Pylint.
Line: 19
Column: 1
Period,
algos,
)
from pandas._libs.tslibs import conversion
from pandas._typing import (
ArrayLike,
DtypeObj,
)
Reported by Pylint.
Line: 265
Column: 8
"""
global _is_scipy_sparse
if _is_scipy_sparse is None:
try:
from scipy.sparse import issparse as _is_scipy_sparse
except ImportError:
_is_scipy_sparse = lambda _: False
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
Line: 37
Column: 1
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.inference import ( # noqa:F401
is_array_like,
is_bool,
is_complex,
is_dataclass,
is_decimal,
Reported by Pylint.
pandas/tests/util/test_assert_series_equal.py
51 issues
Line: 1
Column: 1
import pytest
import pandas as pd
from pandas import (
Categorical,
DataFrame,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 69
Column: 5
The arguments passed to `tm.assert_series_equal`.
"""
_assert_not_series_equal(a, b, **kwargs)
_assert_not_series_equal(b, a, **kwargs)
@pytest.mark.parametrize("data", [range(3), list("abc"), list("áàä")])
def test_series_equal(data):
_assert_series_equal_both(Series(data), Series(data))
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas as pd
from pandas import (
Categorical,
DataFrame,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 12
Column: 1
import pandas._testing as tm
def _assert_series_equal_both(a, b, **kwargs):
"""
Check that two Series equal.
This check is performed commutatively.
Reported by Pylint.
Line: 12
Column: 1
import pandas._testing as tm
def _assert_series_equal_both(a, b, **kwargs):
"""
Check that two Series equal.
This check is performed commutatively.
Reported by Pylint.
Line: 31
Column: 1
tm.assert_series_equal(b, a, **kwargs)
def _assert_not_series_equal(a, b, **kwargs):
"""
Check that two Series are not equal.
Parameters
----------
Reported by Pylint.
Line: 31
Column: 1
tm.assert_series_equal(b, a, **kwargs)
def _assert_not_series_equal(a, b, **kwargs):
"""
Check that two Series are not equal.
Parameters
----------
Reported by Pylint.
Line: 53
Column: 1
pass
def _assert_not_series_equal_both(a, b, **kwargs):
"""
Check that two Series are not equal.
This check is performed commutatively.
Reported by Pylint.
Line: 53
Column: 1
pass
def _assert_not_series_equal_both(a, b, **kwargs):
"""
Check that two Series are not equal.
This check is performed commutatively.
Reported by Pylint.
Line: 73
Column: 1
@pytest.mark.parametrize("data", [range(3), list("abc"), list("áàä")])
def test_series_equal(data):
_assert_series_equal_both(Series(data), Series(data))
@pytest.mark.parametrize(
"data1,data2",
Reported by Pylint.
pandas/tests/indexing/multiindex/test_partial.py
51 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
DataFrame,
Float64Index,
Int64Index,
Reported by Pylint.
Line: 37
Column: 13
# missing item:
with pytest.raises(KeyError, match="1"):
df[1]
with pytest.raises(KeyError, match=r"'\[1\] not in index'"):
df[[1]]
def test_series_slice_partial(self):
pass
Reported by Pylint.
Line: 39
Column: 13
with pytest.raises(KeyError, match="1"):
df[1]
with pytest.raises(KeyError, match=r"'\[1\] not in index'"):
df[[1]]
def test_series_slice_partial(self):
pass
def test_xs_partial(
Reported by Pylint.
Line: 118
Column: 13
tm.assert_frame_equal(result, expected)
with pytest.raises(KeyError, match=r"\('a', 'foo'\)"):
df.loc[("a", "foo"), :]
# TODO(ArrayManager) rewrite test to not use .values
# exp.loc[2000, 4].values[:] select multiple columns -> .values is not a view
@td.skip_array_manager_invalid_test
def test_partial_set(self, multiindex_year_month_day_dataframe_random_data):
Reported by Pylint.
Line: 120
Column: 3
with pytest.raises(KeyError, match=r"\('a', 'foo'\)"):
df.loc[("a", "foo"), :]
# TODO(ArrayManager) rewrite test to not use .values
# exp.loc[2000, 4].values[:] select multiple columns -> .values is not a view
@td.skip_array_manager_invalid_test
def test_partial_set(self, multiindex_year_month_day_dataframe_random_data):
# GH #397
ymd = multiindex_year_month_day_dataframe_random_data
Reported by Pylint.
Line: 161
Column: 20
assert isinstance(mi.levels[0], Float64Index)
assert 14 not in mi.levels[0]
assert not mi.levels[0]._should_fallback_to_positional
assert not mi._should_fallback_to_positional
with pytest.raises(KeyError, match="14"):
ser[14]
with pytest.raises(KeyError, match="14"):
Reported by Pylint.
Line: 162
Column: 20
assert 14 not in mi.levels[0]
assert not mi.levels[0]._should_fallback_to_positional
assert not mi._should_fallback_to_positional
with pytest.raises(KeyError, match="14"):
ser[14]
with pytest.raises(KeyError, match="14"):
with tm.assert_produces_warning(FutureWarning):
Reported by Pylint.
Line: 165
Column: 13
assert not mi._should_fallback_to_positional
with pytest.raises(KeyError, match="14"):
ser[14]
with pytest.raises(KeyError, match="14"):
with tm.assert_produces_warning(FutureWarning):
mi.get_value(ser, 14)
# ---------------------------------------------------------------------
Reported by Pylint.
Line: 182
Column: 3
tm.assert_series_equal(result, expected)
# need to put in some work here
# FIXME: dont leave commented-out
# self.ymd.loc[2000, 0] = 0
# assert (self.ymd.loc[2000]['A'] == 0).all()
# Pretty sure the second (and maybe even the first) is already wrong.
with pytest.raises(KeyError, match="6"):
Reported by Pylint.
Line: 188
Column: 13
# Pretty sure the second (and maybe even the first) is already wrong.
with pytest.raises(KeyError, match="6"):
ymd.loc[(2000, 6)]
with pytest.raises(KeyError, match="(2000, 6)"):
ymd.loc[(2000, 6), 0]
# ---------------------------------------------------------------------
Reported by Pylint.
pandas/tests/indexes/base_class/test_setops.py
50 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pandas as pd
from pandas import (
Index,
Series,
Reported by Pylint.
Line: 37
Column: 18
result = idx.intersection(idx[1:][::-1])
tm.assert_index_equal(result, expected)
result = idx._union(idx[1:], sort=None)
expected = idx
tm.assert_numpy_array_equal(result, expected.values)
result = idx.union(idx[1:], sort=None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 46
Column: 18
# if other is not monotonic increasing, _union goes through
# a different route
result = idx._union(idx[1:][::-1], sort=None)
tm.assert_numpy_array_equal(result, expected.values)
result = idx.union(idx[1:][::-1], sort=None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 93
Column: 3
@pytest.mark.xfail(reason="GH#25151 need to decide on True behavior")
def test_union_sort_other_incomparable_true(self):
# TODO decide on True behaviour
# sort=True
idx = Index([1, pd.Timestamp("2000")])
with pytest.raises(TypeError, match=".*"):
idx.union(idx[:1], sort=True)
Reported by Pylint.
Line: 101
Column: 3
@pytest.mark.xfail(reason="GH#25151 need to decide on True behavior")
def test_intersection_equal_sort_true(self):
# TODO decide on True behaviour
idx = Index(["c", "a", "b"])
sorted_ = Index(["a", "b", "c"])
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
def test_intersection_base(self, sort):
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pandas as pd
from pandas import (
Index,
Series,
Reported by Pylint.
Line: 15
Column: 1
from pandas.core.algorithms import safe_sort
class TestIndexSetOps:
@pytest.mark.parametrize(
"method", ["union", "intersection", "difference", "symmetric_difference"]
)
def test_setops_disallow_true(self, method):
idx1 = Index(["a", "b"])
Reported by Pylint.
Line: 18
Column: 5
class TestIndexSetOps:
@pytest.mark.parametrize(
"method", ["union", "intersection", "difference", "symmetric_difference"]
)
def test_setops_disallow_true(self, method):
idx1 = Index(["a", "b"])
idx2 = Index(["b", "c"])
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
Reported by Pylint.
Line: 18
Column: 5
class TestIndexSetOps:
@pytest.mark.parametrize(
"method", ["union", "intersection", "difference", "symmetric_difference"]
)
def test_setops_disallow_true(self, method):
idx1 = Index(["a", "b"])
idx2 = Index(["b", "c"])
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
Reported by Pylint.
Line: 26
Column: 5
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
getattr(idx1, method)(idx2, sort=True)
def test_setops_preserve_object_dtype(self):
idx = Index([1, 2, 3], dtype=object)
result = idx.intersection(idx[1:])
expected = idx[1:]
tm.assert_index_equal(result, expected)
Reported by Pylint.
asv_bench/benchmarks/io/sql.py
50 issues
Line: 6
Column: 1
import numpy as np
from sqlalchemy import create_engine
from pandas import (
DataFrame,
date_range,
read_sql_query,
read_sql_table,
)
Reported by Pylint.
Line: 13
Column: 1
read_sql_table,
)
from ..pandas_vb_common import tm
class SQL:
params = ["sqlalchemy", "sqlite"]
Reported by Pylint.
Line: 151
Column: 1
read_sql_table(self.table_name, self.con, columns=[dtype])
from ..pandas_vb_common import setup # noqa: F401 isort:skip
Reported by Pylint.
Line: 27
Column: 9
"sqlalchemy": create_engine("sqlite:///:memory:"),
"sqlite": sqlite3.connect(":memory:"),
}
self.table_name = "test_type"
self.query_all = f"SELECT * FROM {self.table_name}"
self.con = con[connection]
self.df = DataFrame(
{
"float": np.random.randn(N),
Reported by Pylint.
Line: 28
Column: 9
"sqlite": sqlite3.connect(":memory:"),
}
self.table_name = "test_type"
self.query_all = f"SELECT * FROM {self.table_name}"
self.con = con[connection]
self.df = DataFrame(
{
"float": np.random.randn(N),
"float_with_nan": np.random.randn(N),
Reported by Pylint.
Line: 28
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b608_hardcoded_sql_expressions.html
"sqlite": sqlite3.connect(":memory:"),
}
self.table_name = "test_type"
self.query_all = f"SELECT * FROM {self.table_name}"
self.con = con[connection]
self.df = DataFrame(
{
"float": np.random.randn(N),
"float_with_nan": np.random.randn(N),
Reported by Bandit.
Line: 29
Column: 9
}
self.table_name = "test_type"
self.query_all = f"SELECT * FROM {self.table_name}"
self.con = con[connection]
self.df = DataFrame(
{
"float": np.random.randn(N),
"float_with_nan": np.random.randn(N),
"string": ["foo"] * N,
Reported by Pylint.
Line: 30
Column: 9
self.table_name = "test_type"
self.query_all = f"SELECT * FROM {self.table_name}"
self.con = con[connection]
self.df = DataFrame(
{
"float": np.random.randn(N),
"float_with_nan": np.random.randn(N),
"string": ["foo"] * N,
"bool": [True] * N,
Reported by Pylint.
Line: 45
Column: 37
self.df["datetime_string"] = self.df["datetime"].astype(str)
self.df.to_sql(self.table_name, self.con, if_exists="replace")
def time_to_sql_dataframe(self, connection):
self.df.to_sql("test1", self.con, if_exists="replace")
def time_read_sql_query(self, connection):
read_sql_query(self.query_all, self.con)
Reported by Pylint.
Line: 48
Column: 35
def time_to_sql_dataframe(self, connection):
self.df.to_sql("test1", self.con, if_exists="replace")
def time_read_sql_query(self, connection):
read_sql_query(self.query_all, self.con)
class WriteSQLDtypes:
Reported by Pylint.
pandas/core/internals/concat.py
50 issues
Line: 13
Column: 1
import numpy as np
from pandas._libs import (
NaT,
internals as libinternals,
)
from pandas._libs.missing import NA
from pandas._typing import (
Reported by Pylint.
Line: 17
Column: 1
NaT,
internals as libinternals,
)
from pandas._libs.missing import NA
from pandas._typing import (
ArrayLike,
DtypeObj,
Manager,
Shape,
Reported by Pylint.
Line: 17
Column: 1
NaT,
internals as libinternals,
)
from pandas._libs.missing import NA
from pandas._typing import (
ArrayLike,
DtypeObj,
Manager,
Shape,
Reported by Pylint.
Line: 69
Column: 57
def _concatenate_array_managers(
mgrs_indexers, axes: list[Index], concat_axis: int, copy: bool
) -> Manager:
"""
Concatenate array managers into one.
Parameters
Reported by Pylint.
Line: 96
Column: 3
if concat_axis == 1:
# concatting along the rows -> concat the reindexed arrays
# TODO(ArrayManager) doesn't yet preserve the correct dtype
arrays = [
concat_arrays([mgrs[i].arrays[j] for i in range(len(mgrs))])
for j in range(len(mgrs[0].arrays))
]
else:
Reported by Pylint.
Line: 152
Column: 16
arr.to_array(target_dtype) if isinstance(arr, NullArrayProxy) else arr
for arr in to_concat
]
return type(to_concat_no_proxy[0])._concat_same_type(to_concat, axis=0)
to_concat = [
arr.to_array(target_dtype)
if isinstance(arr, NullArrayProxy)
else cast_to_common_type(arr, target_dtype)
Reported by Pylint.
Line: 163
Column: 16
if isinstance(to_concat[0], ExtensionArray):
cls = type(to_concat[0])
return cls._concat_same_type(to_concat)
result = np.concatenate(to_concat)
# TODO decide on exact behaviour (we shouldn't do this only for empty result)
# see https://github.com/pandas-dev/pandas/issues/39817
Reported by Pylint.
Line: 167
Column: 3
result = np.concatenate(to_concat)
# TODO decide on exact behaviour (we shouldn't do this only for empty result)
# see https://github.com/pandas-dev/pandas/issues/39817
if len(result) == 0:
# all empties -> check for bool to not coerce to float
kinds = {obj.dtype.kind for obj in to_concat_no_proxy}
if len(kinds) != 1:
Reported by Pylint.
Line: 179
Column: 57
def concatenate_managers(
mgrs_indexers, axes: list[Index], concat_axis: int, copy: bool
) -> Manager:
"""
Concatenate block managers into one.
Parameters
Reported by Pylint.
Line: 195
Column: 3
-------
BlockManager
"""
# TODO(ArrayManager) this assumes that all managers are of the same type
if isinstance(mgrs_indexers[0][0], ArrayManager):
return _concatenate_array_managers(mgrs_indexers, axes, concat_axis, copy)
concat_plans = [
_get_mgr_concatenation_plan(mgr, indexers) for mgr, indexers in mgrs_indexers
Reported by Pylint.
pandas/tests/frame/methods/test_clip.py
50 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 47
Column: 3
assert (clipped_df.values[mask] == df.values[mask]).all()
def test_clip_mixed_numeric(self):
# TODO(jreback)
# clip on mixed integer or floats
# with integer clippers coerces to float
df = DataFrame({"A": [1, 2, 3], "B": [1.0, np.nan, 3.0]})
result = df.clip(1, 2)
expected = DataFrame({"A": [1, 2, 2], "B": [1.0, np.nan, 2.0]})
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 11
Column: 1
import pandas._testing as tm
class TestDataFrameClip:
def test_clip(self, float_frame):
median = float_frame.median().median()
original = float_frame.copy()
double = float_frame.clip(upper=median, lower=median)
Reported by Pylint.
Line: 12
Column: 5
class TestDataFrameClip:
def test_clip(self, float_frame):
median = float_frame.median().median()
original = float_frame.copy()
double = float_frame.clip(upper=median, lower=median)
assert not (double.values != median).any()
Reported by Pylint.
Line: 12
Column: 5
class TestDataFrameClip:
def test_clip(self, float_frame):
median = float_frame.median().median()
original = float_frame.copy()
double = float_frame.clip(upper=median, lower=median)
assert not (double.values != median).any()
Reported by Pylint.
Line: 17
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
original = float_frame.copy()
double = float_frame.clip(upper=median, lower=median)
assert not (double.values != median).any()
# Verify that float_frame was not changed inplace
assert (float_frame.values == original.values).all()
def test_inplace_clip(self, float_frame):
Reported by Bandit.
Line: 20
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert not (double.values != median).any()
# Verify that float_frame was not changed inplace
assert (float_frame.values == original.values).all()
def test_inplace_clip(self, float_frame):
# GH#15388
median = float_frame.median().median()
frame_copy = float_frame.copy()
Reported by Bandit.
Line: 22
Column: 5
# Verify that float_frame was not changed inplace
assert (float_frame.values == original.values).all()
def test_inplace_clip(self, float_frame):
# GH#15388
median = float_frame.median().median()
frame_copy = float_frame.copy()
return_value = frame_copy.clip(upper=median, lower=median, inplace=True)
Reported by Pylint.
Line: 22
Column: 5
# Verify that float_frame was not changed inplace
assert (float_frame.values == original.values).all()
def test_inplace_clip(self, float_frame):
# GH#15388
median = float_frame.median().median()
frame_copy = float_frame.copy()
return_value = frame_copy.clip(upper=median, lower=median, inplace=True)
Reported by Pylint.
pandas/tests/arithmetic/test_interval.py
50 issues
Line: 4
Column: 1
import operator
import numpy as np
import pytest
from pandas.core.dtypes.common import is_list_like
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 53
Column: 20
@pytest.fixture
def interval_array(left_right_dtypes):
"""
Fixture to generate an IntervalArray of various dtypes containing NA if possible
"""
left, right = left_right_dtypes
return IntervalArray.from_arrays(left, right)
Reported by Pylint.
Line: 101
Column: 42
"""
return request.param
def elementwise_comparison(self, op, interval_array, other):
"""
Helper that performs elementwise comparisons between `array` and `other`
"""
other = other if is_list_like(other) else [other] * len(interval_array)
expected = np.array([op(x, y) for x, y in zip(interval_array, other)])
Reported by Pylint.
Line: 111
Column: 48
return Series(expected, index=other.index)
return expected
def test_compare_scalar_interval(self, op, interval_array):
# matches first interval
other = interval_array[0]
result = op(interval_array, other)
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_numpy_array_equal(result, expected)
Reported by Pylint.
Line: 125
Column: 9
tm.assert_numpy_array_equal(result, expected)
def test_compare_scalar_interval_mixed_closed(self, op, closed, other_closed):
interval_array = IntervalArray.from_arrays(range(2), range(1, 3), closed=closed)
other = Interval(0, 1, closed=other_closed)
result = op(interval_array, other)
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_numpy_array_equal(result, expected)
Reported by Pylint.
Line: 132
Column: 42
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_numpy_array_equal(result, expected)
def test_compare_scalar_na(self, op, interval_array, nulls_fixture, request):
result = op(interval_array, nulls_fixture)
expected = self.elementwise_comparison(op, interval_array, nulls_fixture)
if nulls_fixture is pd.NA and interval_array.dtype.subtype != "int64":
mark = pytest.mark.xfail(
Reported by Pylint.
Line: 158
Column: 45
Period("2017-01-01", "D"),
],
)
def test_compare_scalar_other(self, op, interval_array, other):
result = op(interval_array, other)
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_numpy_array_equal(result, expected)
def test_compare_list_like_interval(self, op, interval_array, interval_constructor):
Reported by Pylint.
Line: 163
Column: 51
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_numpy_array_equal(result, expected)
def test_compare_list_like_interval(self, op, interval_array, interval_constructor):
# same endpoints
other = interval_constructor(interval_array.left, interval_array.right)
result = op(interval_array, other)
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_equal(result, expected)
Reported by Pylint.
Line: 187
Column: 9
def test_compare_list_like_interval_mixed_closed(
self, op, interval_constructor, closed, other_closed
):
interval_array = IntervalArray.from_arrays(range(2), range(1, 3), closed=closed)
other = interval_constructor(range(2), range(1, 3), closed=other_closed)
result = op(interval_array, other)
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_equal(result, expected)
Reported by Pylint.
Line: 212
Column: 49
),
],
)
def test_compare_list_like_object(self, op, interval_array, other):
result = op(interval_array, other)
expected = self.elementwise_comparison(op, interval_array, other)
tm.assert_numpy_array_equal(result, expected)
def test_compare_list_like_nan(self, op, interval_array, nulls_fixture, request):
Reported by Pylint.