The following issues were found
pandas/tests/extension/test_boolean.py
85 issues
Line: 17
Column: 1
"""
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.boolean import BooleanDtype
from pandas.tests.extension import base
Reported by Pylint.
Line: 35
Column: 10
@pytest.fixture
def data(dtype):
return pd.array(make_data(), dtype=dtype)
@pytest.fixture
def data_for_twos(dtype):
Reported by Pylint.
Line: 40
Column: 19
@pytest.fixture
def data_for_twos(dtype):
return pd.array(np.ones(100), dtype=dtype)
@pytest.fixture
def data_missing(dtype):
Reported by Pylint.
Line: 45
Column: 18
@pytest.fixture
def data_missing(dtype):
return pd.array([np.nan, True], dtype=dtype)
@pytest.fixture
def data_for_sorting(dtype):
Reported by Pylint.
Line: 50
Column: 22
@pytest.fixture
def data_for_sorting(dtype):
return pd.array([True, True, False], dtype=dtype)
@pytest.fixture
def data_missing_for_sorting(dtype):
Reported by Pylint.
Line: 55
Column: 30
@pytest.fixture
def data_missing_for_sorting(dtype):
return pd.array([True, np.nan, False], dtype=dtype)
@pytest.fixture
def na_cmp():
Reported by Pylint.
Line: 71
Column: 23
@pytest.fixture
def data_for_grouping(dtype):
b = True
a = False
na = np.nan
return pd.array([b, b, na, na, a, a, b], dtype=dtype)
Reported by Pylint.
Line: 109
Column: 5
# overwriting to indicate ops don't raise an error
super().check_opname(s, op_name, other, exc=None)
def _check_op(self, obj, op, other, op_name, exc=NotImplementedError):
if exc is None:
if op_name in self.implements:
msg = r"numpy boolean subtract"
with pytest.raises(TypeError, match=msg):
op(obj, other)
Reported by Pylint.
Line: 153
Column: 33
# overwriting to indicate ops don't raise an error
super().check_opname(s, op_name, other, exc=None)
def _compare_other(self, s, data, op_name, other):
self.check_opname(s, op_name, other)
@pytest.mark.skip(reason="Tested in tests/arrays/test_boolean.py")
def test_compare_scalar(self, data, all_compare_operators):
pass
Reported by Pylint.
Line: 157
Column: 35
self.check_opname(s, op_name, other)
@pytest.mark.skip(reason="Tested in tests/arrays/test_boolean.py")
def test_compare_scalar(self, data, all_compare_operators):
pass
@pytest.mark.skip(reason="Tested in tests/arrays/test_boolean.py")
def test_compare_array(self, data, all_compare_operators):
pass
Reported by Pylint.
pandas/tests/arrays/categorical/test_indexing.py
85 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
Categorical,
CategoricalIndex,
Index,
Interval,
IntervalIndex,
Reported by Pylint.
Line: 26
Column: 37
assert self.factor[-1] == "c"
subf = self.factor[[0, 1, 2]]
tm.assert_numpy_array_equal(subf._codes, np.array([0, 1, 1], dtype=np.int8))
subf = self.factor[np.asarray(self.factor) == "c"]
tm.assert_numpy_array_equal(subf._codes, np.array([2, 2, 2], dtype=np.int8))
def test_setitem(self):
Reported by Pylint.
Line: 29
Column: 37
tm.assert_numpy_array_equal(subf._codes, np.array([0, 1, 1], dtype=np.int8))
subf = self.factor[np.asarray(self.factor) == "c"]
tm.assert_numpy_array_equal(subf._codes, np.array([2, 2, 2], dtype=np.int8))
def test_setitem(self):
# int/positional
c = self.factor.copy()
Reported by Pylint.
Line: 149
Column: 37
str(cat1)
exp_arr = np.array([0, 0, 1, 1, 2, 2], dtype=np.int8)
exp_idx = PeriodIndex(["2014-01", "2014-02", "2014-03"], freq="M")
tm.assert_numpy_array_equal(cat1._codes, exp_arr)
tm.assert_index_equal(cat1.categories, exp_idx)
idx2 = PeriodIndex(
["2014-03", "2014-03", "2014-02", "2014-01", "2014-03", "2014-01"], freq="M"
)
Reported by Pylint.
Line: 159
Column: 37
str(cat2)
exp_arr = np.array([2, 2, 1, 0, 2, 0], dtype=np.int8)
exp_idx2 = PeriodIndex(["2014-01", "2014-02", "2014-03"], freq="M")
tm.assert_numpy_array_equal(cat2._codes, exp_arr)
tm.assert_index_equal(cat2.categories, exp_idx2)
idx3 = PeriodIndex(
[
"2013-12",
Reported by Pylint.
Line: 188
Column: 37
],
freq="M",
)
tm.assert_numpy_array_equal(cat3._codes, exp_arr)
tm.assert_index_equal(cat3.categories, exp_idx)
def test_categories_assignments(self):
s = Categorical(["a", "b", "c", "a"])
exp = np.array([1, 2, 3, 1], dtype=np.int64)
Reported by Pylint.
Line: 320
Column: 13
assert "a" not in cat
with pytest.raises(TypeError, match="unhashable type"):
["a"] in cat
with pytest.raises(TypeError, match="unhashable type"):
["a", "b"] in cat
Reported by Pylint.
Line: 323
Column: 13
["a"] in cat
with pytest.raises(TypeError, match="unhashable type"):
["a", "b"] in cat
@pytest.mark.parametrize("index", [True, False])
def test_mask_with_boolean(index):
s = Series(range(3))
Reported by Pylint.
Line: 363
Column: 3
ValueError
When Categorical.__array__ is called.
"""
# TODO(Categorical): identify other places where this may be
# useful and move to a conftest.py
def array(self, dtype=None):
raise ValueError("I cannot be converted.")
with monkeypatch.context() as m:
Reported by Pylint.
Line: 373
Column: 20
yield
def test_series_at(non_coercible_categorical):
arr = Categorical(["a", "b", "c"])
ser = Series(arr)
result = ser.at[0]
assert result == "a"
Reported by Pylint.
pandas/tests/frame/methods/test_values.py
84 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
DataFrame,
NaT,
Series,
Reported by Pylint.
Line: 229
Column: 42
class TestPrivateValues:
def test_private_values_dt64tz(self, request):
dta = date_range("2000", periods=4, tz="US/Central")._data.reshape(-1, 1)
df = DataFrame(dta, columns=["A"])
tm.assert_equal(df._values, dta)
Reported by Pylint.
Line: 231
Column: 15
class TestPrivateValues:
def test_private_values_dt64tz(self, request):
dta = date_range("2000", periods=4, tz="US/Central")._data.reshape(-1, 1)
df = DataFrame(dta, columns=["A"])
tm.assert_equal(df._values, dta)
# we have a view
Reported by Pylint.
Line: 234
Column: 25
dta = date_range("2000", periods=4, tz="US/Central")._data.reshape(-1, 1)
df = DataFrame(dta, columns=["A"])
tm.assert_equal(df._values, dta)
# we have a view
assert np.shares_memory(df._values._ndarray, dta._ndarray)
# TimedeltaArray
Reported by Pylint.
Line: 237
Column: 54
tm.assert_equal(df._values, dta)
# we have a view
assert np.shares_memory(df._values._ndarray, dta._ndarray)
# TimedeltaArray
tda = dta - dta
df2 = df - df
tm.assert_equal(df2._values, tda)
Reported by Pylint.
Line: 237
Column: 33
tm.assert_equal(df._values, dta)
# we have a view
assert np.shares_memory(df._values._ndarray, dta._ndarray)
# TimedeltaArray
tda = dta - dta
df2 = df - df
tm.assert_equal(df2._values, tda)
Reported by Pylint.
Line: 237
Column: 33
tm.assert_equal(df._values, dta)
# we have a view
assert np.shares_memory(df._values._ndarray, dta._ndarray)
# TimedeltaArray
tda = dta - dta
df2 = df - df
tm.assert_equal(df2._values, tda)
Reported by Pylint.
Line: 242
Column: 25
# TimedeltaArray
tda = dta - dta
df2 = df - df
tm.assert_equal(df2._values, tda)
@td.skip_array_manager_invalid_test
def test_private_values_dt64tz_multicol(self):
dta = date_range("2000", periods=8, tz="US/Central")._data.reshape(-1, 2)
Reported by Pylint.
Line: 246
Column: 15
@td.skip_array_manager_invalid_test
def test_private_values_dt64tz_multicol(self):
dta = date_range("2000", periods=8, tz="US/Central")._data.reshape(-1, 2)
df = DataFrame(dta, columns=["A", "B"])
tm.assert_equal(df._values, dta)
# we have a view
Reported by Pylint.
Line: 249
Column: 25
dta = date_range("2000", periods=8, tz="US/Central")._data.reshape(-1, 2)
df = DataFrame(dta, columns=["A", "B"])
tm.assert_equal(df._values, dta)
# we have a view
assert np.shares_memory(df._values._ndarray, dta._ndarray)
# TimedeltaArray
Reported by Pylint.
pandas/tests/scalar/timedelta/test_constructors.py
84 issues
Line: 5
Column: 1
from itertools import product
import numpy as np
import pytest
from pandas._libs.tslibs import OutOfBoundsTimedelta
from pandas import (
Timedelta,
Reported by Pylint.
Line: 187
Column: 22
assert Timedelta(td.value) == td
assert Timedelta(str(td)) == td
assert Timedelta(td._repr_base(format="all")) == td
assert Timedelta(td._repr_base()) == td
def test_overflow_on_construction():
msg = "int too (large|big) to convert"
Reported by Pylint.
Line: 188
Column: 22
assert Timedelta(str(td)) == td
assert Timedelta(td._repr_base(format="all")) == td
assert Timedelta(td._repr_base()) == td
def test_overflow_on_construction():
msg = "int too (large|big) to convert"
Reported by Pylint.
Line: 219
Column: 3
],
)
def test_construction_out_of_bounds_td64(val, unit, name):
# TODO: parametrize over units just above/below the implementation bounds
# once GH#38964 is resolved
# Timedelta.max is just under 106752 days
td64 = np.timedelta64(val, unit)
assert td64.astype("m8[ns]").view("i8") < 0 # i.e. naive astype will be wrong
Reported by Pylint.
Line: 1
Column: 1
from datetime import timedelta
from itertools import product
import numpy as np
import pytest
from pandas._libs.tslibs import OutOfBoundsTimedelta
from pandas import (
Reported by Pylint.
Line: 16
Column: 1
)
def test_construction():
expected = np.timedelta64(10, "D").astype("m8[ns]").view("i8")
assert Timedelta(10, unit="d").value == expected
assert Timedelta(10.0, unit="d").value == expected
assert Timedelta("10 days").value == expected
assert Timedelta(days=10).value == expected
Reported by Pylint.
Line: 16
Column: 1
)
def test_construction():
expected = np.timedelta64(10, "D").astype("m8[ns]").view("i8")
assert Timedelta(10, unit="d").value == expected
assert Timedelta(10.0, unit="d").value == expected
assert Timedelta("10 days").value == expected
assert Timedelta(days=10).value == expected
Reported by Pylint.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_construction():
expected = np.timedelta64(10, "D").astype("m8[ns]").view("i8")
assert Timedelta(10, unit="d").value == expected
assert Timedelta(10.0, unit="d").value == expected
assert Timedelta("10 days").value == expected
assert Timedelta(days=10).value == expected
assert Timedelta(days=10.0).value == expected
Reported by Bandit.
Line: 19
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_construction():
expected = np.timedelta64(10, "D").astype("m8[ns]").view("i8")
assert Timedelta(10, unit="d").value == expected
assert Timedelta(10.0, unit="d").value == expected
assert Timedelta("10 days").value == expected
assert Timedelta(days=10).value == expected
assert Timedelta(days=10.0).value == expected
expected += np.timedelta64(10, "s").astype("m8[ns]").view("i8")
Reported by Bandit.
Line: 20
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected = np.timedelta64(10, "D").astype("m8[ns]").view("i8")
assert Timedelta(10, unit="d").value == expected
assert Timedelta(10.0, unit="d").value == expected
assert Timedelta("10 days").value == expected
assert Timedelta(days=10).value == expected
assert Timedelta(days=10.0).value == expected
expected += np.timedelta64(10, "s").astype("m8[ns]").view("i8")
assert Timedelta("10 days 00:00:10").value == expected
Reported by Bandit.
pandas/tests/indexes/multi/test_equivalence.py
83 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
Index,
MultiIndex,
Series,
)
Reported by Pylint.
Line: 218
Column: 14
def test_equals_missing_values():
# make sure take is not using -1
i = MultiIndex.from_tuples([(0, pd.NaT), (0, pd.Timestamp("20130101"))])
result = i[0:1].equals(i[0])
assert not result
result = i[1:2].equals(i[1])
assert not result
Reported by Pylint.
Line: 220
Column: 14
i = MultiIndex.from_tuples([(0, pd.NaT), (0, pd.Timestamp("20130101"))])
result = i[0:1].equals(i[0])
assert not result
result = i[1:2].equals(i[1])
assert not result
def test_equals_missing_values_differently_sorted():
# GH#38439
Reported by Pylint.
Line: 41
Column: 9
index_c = index_a[0:-1].append(index_a[-2:-1])
index_d = index_a[0:1]
with pytest.raises(ValueError, match="Lengths must match"):
index_a == index_b
expected1 = np.array([True] * n)
expected2 = np.array([True] * (n - 1) + [False])
tm.assert_numpy_array_equal(index_a == index_a, expected1)
tm.assert_numpy_array_equal(index_a == index_c, expected2)
Reported by Pylint.
Line: 53
Column: 9
array_c = np.array(index_a[0:-1].append(index_a[-2:-1]))
array_d = np.array(index_a[0:1])
with pytest.raises(ValueError, match="Lengths must match"):
index_a == array_b
tm.assert_numpy_array_equal(index_a == array_a, expected1)
tm.assert_numpy_array_equal(index_a == array_c, expected2)
# test comparisons with Series
series_a = Series(array_a)
Reported by Pylint.
Line: 63
Column: 9
series_c = Series(array_c)
series_d = Series(array_d)
with pytest.raises(ValueError, match="Lengths must match"):
index_a == series_b
tm.assert_numpy_array_equal(index_a == series_a, expected1)
tm.assert_numpy_array_equal(index_a == series_c, expected2)
# cases where length is 1 for one of them
Reported by Pylint.
Line: 70
Column: 9
# cases where length is 1 for one of them
with pytest.raises(ValueError, match="Lengths must match"):
index_a == index_d
with pytest.raises(ValueError, match="Lengths must match"):
index_a == series_d
with pytest.raises(ValueError, match="Lengths must match"):
index_a == array_d
msg = "Can only compare identically-labeled Series objects"
Reported by Pylint.
Line: 72
Column: 9
with pytest.raises(ValueError, match="Lengths must match"):
index_a == index_d
with pytest.raises(ValueError, match="Lengths must match"):
index_a == series_d
with pytest.raises(ValueError, match="Lengths must match"):
index_a == array_d
msg = "Can only compare identically-labeled Series objects"
with pytest.raises(ValueError, match=msg):
series_a == series_d
Reported by Pylint.
Line: 74
Column: 9
with pytest.raises(ValueError, match="Lengths must match"):
index_a == series_d
with pytest.raises(ValueError, match="Lengths must match"):
index_a == array_d
msg = "Can only compare identically-labeled Series objects"
with pytest.raises(ValueError, match=msg):
series_a == series_d
with pytest.raises(ValueError, match="Lengths must match"):
series_a == array_d
Reported by Pylint.
Line: 77
Column: 9
index_a == array_d
msg = "Can only compare identically-labeled Series objects"
with pytest.raises(ValueError, match=msg):
series_a == series_d
with pytest.raises(ValueError, match="Lengths must match"):
series_a == array_d
# comparing with a scalar should broadcast; note that we are excluding
# MultiIndex because in this case each item in the index is a tuple of
Reported by Pylint.
pandas/tests/frame/methods/test_to_dict.py
82 issues
Line: 8
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pytz
from pandas import (
DataFrame,
Series,
Reported by Pylint.
Line: 9
Column: 1
import numpy as np
import pytest
import pytz
from pandas import (
DataFrame,
Series,
Timestamp,
Reported by Pylint.
Line: 1
Column: 1
from collections import (
OrderedDict,
defaultdict,
)
from datetime import datetime
import numpy as np
import pytest
import pytz
Reported by Pylint.
Line: 19
Column: 1
import pandas._testing as tm
class TestDataFrameToDict:
def test_to_dict_timestamp(self):
# GH#11247
# split/records producing np.datetime64 rather than Timestamps
# on datetime64[ns] dtypes only
Reported by Pylint.
Line: 20
Column: 5
class TestDataFrameToDict:
def test_to_dict_timestamp(self):
# GH#11247
# split/records producing np.datetime64 rather than Timestamps
# on datetime64[ns] dtypes only
Reported by Pylint.
Line: 20
Column: 5
class TestDataFrameToDict:
def test_to_dict_timestamp(self):
# GH#11247
# split/records producing np.datetime64 rather than Timestamps
# on datetime64[ns] dtypes only
Reported by Pylint.
Line: 33
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected_records = [{"A": tsmp, "B": tsmp}, {"A": tsmp, "B": tsmp}]
expected_records_mixed = [{"A": tsmp, "B": 1}, {"A": tsmp, "B": 2}]
assert test_data.to_dict(orient="records") == expected_records
assert test_data_mixed.to_dict(orient="records") == expected_records_mixed
expected_series = {
"A": Series([tsmp, tsmp], name="A"),
"B": Series([tsmp, tsmp], name="B"),
Reported by Bandit.
Line: 34
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected_records_mixed = [{"A": tsmp, "B": 1}, {"A": tsmp, "B": 2}]
assert test_data.to_dict(orient="records") == expected_records
assert test_data_mixed.to_dict(orient="records") == expected_records_mixed
expected_series = {
"A": Series([tsmp, tsmp], name="A"),
"B": Series([tsmp, tsmp], name="B"),
}
Reported by Bandit.
Line: 66
Column: 5
test_data_mixed.to_dict(orient="split"), expected_split_mixed
)
def test_to_dict_index_not_unique_with_index_orient(self):
# GH#22801
# Data loss when indexes are not unique. Raise ValueError.
df = DataFrame({"a": [1, 2], "b": [0.5, 0.75]}, index=["A", "A"])
msg = "DataFrame index must be unique for orient='index'"
with pytest.raises(ValueError, match=msg):
Reported by Pylint.
Line: 66
Column: 5
test_data_mixed.to_dict(orient="split"), expected_split_mixed
)
def test_to_dict_index_not_unique_with_index_orient(self):
# GH#22801
# Data loss when indexes are not unique. Raise ValueError.
df = DataFrame({"a": [1, 2], "b": [0.5, 0.75]}, index=["A", "A"])
msg = "DataFrame index must be unique for orient='index'"
with pytest.raises(ValueError, match=msg):
Reported by Pylint.
pandas/core/arrays/interval.py
82 issues
Line: 19
Column: 1
from pandas._config import get_option
from pandas._libs import (
NaT,
lib,
)
from pandas._libs.interval import (
VALID_CLOSED,
Reported by Pylint.
Line: 23
Column: 1
NaT,
lib,
)
from pandas._libs.interval import (
VALID_CLOSED,
Interval,
IntervalMixin,
intervals_to_interval_bounds,
)
Reported by Pylint.
Line: 23
Column: 1
NaT,
lib,
)
from pandas._libs.interval import (
VALID_CLOSED,
Interval,
IntervalMixin,
intervals_to_interval_bounds,
)
Reported by Pylint.
Line: 29
Column: 1
IntervalMixin,
intervals_to_interval_bounds,
)
from pandas._libs.missing import NA
from pandas._typing import (
ArrayLike,
Dtype,
NpDtype,
)
Reported by Pylint.
Line: 29
Column: 1
IntervalMixin,
intervals_to_interval_bounds,
)
from pandas._libs.missing import NA
from pandas._typing import (
ArrayLike,
Dtype,
NpDtype,
)
Reported by Pylint.
Line: 1401
Column: 9
"""
Convert myself into a pyarrow Array.
"""
import pyarrow
from pandas.core.arrays._arrow_utils import ArrowIntervalType
try:
subtype = pyarrow.from_numpy_dtype(self.dtype.subtype)
Reported by Pylint.
Line: 324
Column: 9
right = right.copy()
dtype = IntervalDtype(left.dtype, closed=closed)
result._dtype = dtype
result._left = left
result._right = right
if verify_integrity:
result._validate()
Reported by Pylint.
Line: 326
Column: 9
dtype = IntervalDtype(left.dtype, closed=closed)
result._dtype = dtype
result._left = left
result._right = right
if verify_integrity:
result._validate()
return result
Reported by Pylint.
Line: 327
Column: 9
result._dtype = dtype
result._left = left
result._right = right
if verify_integrity:
result._validate()
return result
@classmethod
Reported by Pylint.
Line: 329
Column: 13
result._left = left
result._right = right
if verify_integrity:
result._validate()
return result
@classmethod
def _from_sequence(
cls: type[IntervalArrayT],
Reported by Pylint.
pandas/core/arrays/datetimelike.py
82 issues
Line: 23
Column: 1
import numpy as np
from pandas._libs import (
algos,
lib,
)
from pandas._libs.tslibs import (
BaseOffset,
Reported by Pylint.
Line: 23
Column: 1
import numpy as np
from pandas._libs import (
algos,
lib,
)
from pandas._libs.tslibs import (
BaseOffset,
Reported by Pylint.
Line: 40
Column: 1
iNaT,
to_offset,
)
from pandas._libs.tslibs.fields import (
RoundTo,
round_nsint64,
)
from pandas._libs.tslibs.timestamps import integer_op_not_supported
from pandas._typing import (
Reported by Pylint.
Line: 40
Column: 1
iNaT,
to_offset,
)
from pandas._libs.tslibs.fields import (
RoundTo,
round_nsint64,
)
from pandas._libs.tslibs.timestamps import integer_op_not_supported
from pandas._typing import (
Reported by Pylint.
Line: 44
Column: 1
RoundTo,
round_nsint64,
)
from pandas._libs.tslibs.timestamps import integer_op_not_supported
from pandas._typing import (
ArrayLike,
DatetimeLikeScalar,
Dtype,
DtypeObj,
Reported by Pylint.
Line: 44
Column: 1
RoundTo,
round_nsint64,
)
from pandas._libs.tslibs.timestamps import integer_op_not_supported
from pandas._typing import (
ArrayLike,
DatetimeLikeScalar,
Dtype,
DtypeObj,
Reported by Pylint.
Line: 1316
Column: 13
# specifically _not_ a Tick
result = self._add_offset(-other)
elif isinstance(other, (datetime, np.datetime64)):
result = self._sub_datetimelike_scalar(other)
elif lib.is_integer(other):
# This check must come after the check for np.timedelta64
# as is_integer returns True for these
if not is_period_dtype(self.dtype):
raise integer_op_not_supported(self)
Reported by Pylint.
Line: 1336
Column: 13
result = self._addsub_object_array(other, operator.sub)
elif is_datetime64_dtype(other_dtype) or is_datetime64tz_dtype(other_dtype):
# DatetimeIndex, ndarray[datetime64]
result = self._sub_datetime_arraylike(other)
elif is_period_dtype(other_dtype):
# PeriodIndex
result = self._sub_period_array(other)
elif is_integer_dtype(other_dtype):
if not is_period_dtype(self.dtype):
Reported by Pylint.
Line: 1384
Column: 21
raise TypeError(f"cannot subtract {type(self).__name__} from {other.dtype}")
elif is_timedelta64_dtype(self.dtype):
self = cast("TimedeltaArray", self)
return (-self) + other
# We get here with e.g. datetime objects
return -(self - other)
def __iadd__(self, other):
Reported by Pylint.
Line: 141
Column: 5
return invalid_comparison.
"""
pass
class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray):
"""
Shared Base/Mixin class for DatetimeArray, TimedeltaArray, PeriodArray
Reported by Pylint.
pandas/tests/arrays/categorical/test_dtypes.py
82 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas.core.dtypes.dtypes import CategoricalDtype
from pandas import (
Categorical,
CategoricalIndex,
Index,
Reported by Pylint.
Line: 31
Column: 16
c1 = Categorical(list("aabca"), categories=list("abc"), ordered=False)
c2 = Categorical(list("aabca"), categories=list("cab"), ordered=False)
c3 = Categorical(list("aabca"), categories=list("cab"), ordered=True)
assert c1._categories_match_up_to_permutation(c1)
assert c2._categories_match_up_to_permutation(c2)
assert c3._categories_match_up_to_permutation(c3)
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
Reported by Pylint.
Line: 32
Column: 16
c2 = Categorical(list("aabca"), categories=list("cab"), ordered=False)
c3 = Categorical(list("aabca"), categories=list("cab"), ordered=True)
assert c1._categories_match_up_to_permutation(c1)
assert c2._categories_match_up_to_permutation(c2)
assert c3._categories_match_up_to_permutation(c3)
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
Reported by Pylint.
Line: 33
Column: 16
c3 = Categorical(list("aabca"), categories=list("cab"), ordered=True)
assert c1._categories_match_up_to_permutation(c1)
assert c2._categories_match_up_to_permutation(c2)
assert c3._categories_match_up_to_permutation(c3)
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
Reported by Pylint.
Line: 34
Column: 16
assert c1._categories_match_up_to_permutation(c1)
assert c2._categories_match_up_to_permutation(c2)
assert c3._categories_match_up_to_permutation(c3)
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
assert c1._categories_match_up_to_permutation(
Reported by Pylint.
Line: 35
Column: 20
assert c2._categories_match_up_to_permutation(c2)
assert c3._categories_match_up_to_permutation(c3)
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
assert c1._categories_match_up_to_permutation(
CategoricalIndex(c1, categories=list("cab"))
Reported by Pylint.
Line: 36
Column: 20
assert c3._categories_match_up_to_permutation(c3)
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
assert c1._categories_match_up_to_permutation(
CategoricalIndex(c1, categories=list("cab"))
)
Reported by Pylint.
Line: 37
Column: 20
assert c1._categories_match_up_to_permutation(c2)
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
assert c1._categories_match_up_to_permutation(
CategoricalIndex(c1, categories=list("cab"))
)
assert not c1._categories_match_up_to_permutation(
Reported by Pylint.
Line: 38
Column: 16
assert not c1._categories_match_up_to_permutation(c3)
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
assert c1._categories_match_up_to_permutation(
CategoricalIndex(c1, categories=list("cab"))
)
assert not c1._categories_match_up_to_permutation(
CategoricalIndex(c1, ordered=True)
Reported by Pylint.
Line: 39
Column: 16
assert not c1._categories_match_up_to_permutation(Index(list("aabca")))
assert not c1._categories_match_up_to_permutation(c1.astype(object))
assert c1._categories_match_up_to_permutation(CategoricalIndex(c1))
assert c1._categories_match_up_to_permutation(
CategoricalIndex(c1, categories=list("cab"))
)
assert not c1._categories_match_up_to_permutation(
CategoricalIndex(c1, ordered=True)
)
Reported by Pylint.
pandas/core/reshape/reshape.py
82 issues
Line: 11
Column: 1
import numpy as np
import pandas._libs.reshape as libreshape
from pandas._libs.sparse import IntIndex
from pandas._typing import (
Dtype,
npt,
)
Reported by Pylint.
Line: 11
Column: 1
import numpy as np
import pandas._libs.reshape as libreshape
from pandas._libs.sparse import IntIndex
from pandas._typing import (
Dtype,
npt,
)
Reported by Pylint.
Line: 12
Column: 1
import numpy as np
import pandas._libs.reshape as libreshape
from pandas._libs.sparse import IntIndex
from pandas._typing import (
Dtype,
npt,
)
from pandas.util._decorators import cache_readonly
Reported by Pylint.
Line: 12
Column: 1
import numpy as np
import pandas._libs.reshape as libreshape
from pandas._libs.sparse import IntIndex
from pandas._typing import (
Dtype,
npt,
)
from pandas.util._decorators import cache_readonly
Reported by Pylint.
Line: 142
Column: 9
def _indexer_and_to_sort(
self,
) -> tuple[
npt.NDArray[np.intp],
list[np.ndarray], # each has _some_ signed integer dtype
]:
v = self.level
codes = list(self.index.codes)
Reported by Pylint.
Line: 160
Column: 9
@cache_readonly
def sorted_labels(self):
indexer, to_sort = self._indexer_and_to_sort
return [line.take(indexer) for line in to_sort]
def _make_sorted_values(self, values: np.ndarray) -> np.ndarray:
indexer, _ = self._indexer_and_to_sort
Reported by Pylint.
Line: 164
Column: 9
return [line.take(indexer) for line in to_sort]
def _make_sorted_values(self, values: np.ndarray) -> np.ndarray:
indexer, _ = self._indexer_and_to_sort
sorted_values = algos.take_nd(values, indexer, axis=0)
return sorted_values
def _make_selectors(self):
Reported by Pylint.
Line: 226
Column: 3
# we can simply reshape if we don't have a mask
if mask_all and len(values):
# TODO: Under what circumstances can we rely on sorted_values
# matching values? When that holds, we can slice instead
# of take (in particular for EAs)
new_values = (
sorted_values.reshape(length, width, stride)
.swapaxes(1, 2)
Reported by Pylint.
Line: 247
Column: 30
if isinstance(dtype, ExtensionDtype):
# GH#41875
cls = dtype.construct_array_type()
new_values = cls._empty(result_shape, dtype=dtype)
new_values[:] = fill_value
name = dtype.name
else:
new_values = np.empty(result_shape, dtype=dtype)
new_values.fill(fill_value)
Reported by Pylint.
Line: 293
Column: 24
def get_new_columns(self, value_columns: Index | None):
if value_columns is None:
if self.lift == 0:
return self.removed_level._rename(name=self.removed_name)
lev = self.removed_level.insert(0, item=self.removed_level._na_value)
return lev.rename(self.removed_name)
stride = len(self.removed_level) + self.lift
Reported by Pylint.