The following issues were found
pandas/core/arrays/numeric.py
30 issues
Line: 13
Column: 1
import numpy as np
from pandas._libs import (
Timedelta,
missing as libmissing,
)
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
Reported by Pylint.
Line: 35
Column: 5
)
if TYPE_CHECKING:
import pyarrow
T = TypeVar("T", bound="NumericArray")
class NumericDtype(BaseMaskedDtype):
Reported by Pylint.
Line: 47
Column: 9
"""
Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray.
"""
import pyarrow
from pandas.core.arrays._arrow_utils import pyarrow_array_to_numpy_and_mask
array_class = self.construct_array_type()
Reported by Pylint.
Line: 53
Column: 49
array_class = self.construct_array_type()
pyarrow_type = pyarrow.from_numpy_dtype(self.type)
if not array.type.equals(pyarrow_type):
array = array.cast(pyarrow_type)
if isinstance(array, pyarrow.Array):
chunks = [array]
Reported by Pylint.
Line: 65
Column: 69
results = []
for arr in chunks:
data, mask = pyarrow_array_to_numpy_and_mask(arr, dtype=self.type)
num_arr = array_class(data.copy(), ~mask, copy=False)
results.append(num_arr)
if not results:
return array_class(
Reported by Pylint.
Line: 126
Column: 48
mask = np.where((self._data == 1) & ~self._mask, False, mask)
# x ** 0 is 1.
if omask is not None:
mask = np.where((other == 0) & ~omask, False, mask)
elif other is not libmissing.NA:
mask = np.where(other == 0, False, mask)
elif op_name == "rpow":
# 1 ** x is 1.
Reported by Pylint.
Line: 133
Column: 48
elif op_name == "rpow":
# 1 ** x is 1.
if omask is not None:
mask = np.where((other == 1) & ~omask, False, mask)
elif other is not libmissing.NA:
mask = np.where(other == 1, False, mask)
# x ** 0 is 1.
mask = np.where((self._data == 0) & ~self._mask, False, mask)
Reported by Pylint.
Line: 40
Column: 1
T = TypeVar("T", bound="NumericArray")
class NumericDtype(BaseMaskedDtype):
def __from_arrow__(
self, array: pyarrow.Array | pyarrow.ChunkedArray
) -> BaseMaskedArray:
"""
Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray.
Reported by Pylint.
Line: 77
Column: 20
# avoid additional copy in _concat_same_type
return results[0]
else:
return array_class._concat_same_type(results)
class NumericArray(BaseMaskedArray):
"""
Base class for IntegerArray and FloatingArray.
Reported by Pylint.
Line: 96
Column: 28
raise NotImplementedError("can only perform ops with 1-d structures")
if isinstance(other, NumericArray):
other, omask = other._data, other._mask
elif is_list_like(other):
other = np.asarray(other)
if other.ndim > 1:
raise NotImplementedError("can only perform ops with 1-d structures")
Reported by Pylint.
pandas/tests/frame/constructors/test_from_dict.py
30 issues
Line: 4
Column: 1
from collections import OrderedDict
import numpy as np
import pytest
from pandas import (
DataFrame,
Index,
MultiIndex,
Reported by Pylint.
Line: 116
Column: 21
tm.assert_frame_equal(result, expected)
def test_constructor_orient(self, float_string_frame):
data_dict = float_string_frame.T._series
recons = DataFrame.from_dict(data_dict, orient="index")
expected = float_string_frame.reindex(index=recons.index)
tm.assert_frame_equal(recons, expected)
# dict of sequence
Reported by Pylint.
Line: 1
Column: 1
from collections import OrderedDict
import numpy as np
import pytest
from pandas import (
DataFrame,
Index,
MultiIndex,
Reported by Pylint.
Line: 16
Column: 1
from pandas.core.construction import create_series_with_explicit_dtype
class TestFromDict:
# Note: these tests are specific to the from_dict method, not for
# passing dictionaries to DataFrame.__init__
def test_from_dict_scalars_requires_index(self):
msg = "If using all scalar values, you must pass an index"
Reported by Pylint.
Line: 20
Column: 5
# Note: these tests are specific to the from_dict method, not for
# passing dictionaries to DataFrame.__init__
def test_from_dict_scalars_requires_index(self):
msg = "If using all scalar values, you must pass an index"
with pytest.raises(ValueError, match=msg):
DataFrame.from_dict(OrderedDict([("b", 8), ("a", 5), ("a", 6)]))
def test_constructor_list_of_odicts(self):
Reported by Pylint.
Line: 20
Column: 5
# Note: these tests are specific to the from_dict method, not for
# passing dictionaries to DataFrame.__init__
def test_from_dict_scalars_requires_index(self):
msg = "If using all scalar values, you must pass an index"
with pytest.raises(ValueError, match=msg):
DataFrame.from_dict(OrderedDict([("b", 8), ("a", 5), ("a", 6)]))
def test_constructor_list_of_odicts(self):
Reported by Pylint.
Line: 25
Column: 5
with pytest.raises(ValueError, match=msg):
DataFrame.from_dict(OrderedDict([("b", 8), ("a", 5), ("a", 6)]))
def test_constructor_list_of_odicts(self):
data = [
OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]]),
OrderedDict([["a", 1.5], ["b", 3], ["d", 6]]),
OrderedDict([["a", 1.5], ["d", 6]]),
OrderedDict(),
Reported by Pylint.
Line: 25
Column: 5
with pytest.raises(ValueError, match=msg):
DataFrame.from_dict(OrderedDict([("b", 8), ("a", 5), ("a", 6)]))
def test_constructor_list_of_odicts(self):
data = [
OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]]),
OrderedDict([["a", 1.5], ["b", 3], ["d", 6]]),
OrderedDict([["a", 1.5], ["d", 6]]),
OrderedDict(),
Reported by Pylint.
Line: 41
Column: 5
)
tm.assert_frame_equal(result, expected.reindex(result.index))
def test_constructor_single_row(self):
data = [OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]])]
result = DataFrame(data)
expected = DataFrame.from_dict(dict(zip([0], data)), orient="index").reindex(
result.index
Reported by Pylint.
Line: 41
Column: 5
)
tm.assert_frame_equal(result, expected.reindex(result.index))
def test_constructor_single_row(self):
data = [OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]])]
result = DataFrame(data)
expected = DataFrame.from_dict(dict(zip([0], data)), orient="index").reindex(
result.index
Reported by Pylint.
pandas/tests/indexes/timedeltas/methods/test_insert.py
30 issues
Line: 4
Column: 1
from datetime import timedelta
import numpy as np
import pytest
from pandas._libs import lib
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 6
Column: 1
import numpy as np
import pytest
from pandas._libs import lib
import pandas as pd
from pandas import (
Index,
Timedelta,
Reported by Pylint.
Line: 75
Column: 35
result = idx.insert(n, d)
tm.assert_index_equal(result, expected)
assert result.name == expected.name
assert result.freq == expected.freq
@pytest.mark.parametrize(
"null", [None, np.nan, np.timedelta64("NaT"), pd.NaT, pd.NA]
)
def test_insert_nat(self, null):
Reported by Pylint.
Line: 90
Column: 3
def test_insert_invalid_na(self):
idx = TimedeltaIndex(["4day", "1day", "2day"], name="idx")
# FIXME: assert_index_equal fails if we pass a different
# instance of np.datetime64("NaT")
item = np.datetime64("NaT")
result = idx.insert(0, item)
expected = Index([item] + list(idx), dtype=object, name="idx")
Reported by Pylint.
Line: 1
Column: 1
from datetime import timedelta
import numpy as np
import pytest
from pandas._libs import lib
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 18
Column: 1
import pandas._testing as tm
class TestTimedeltaIndexInsert:
def test_insert(self):
idx = TimedeltaIndex(["4day", "1day", "2day"], name="idx")
result = idx.insert(2, timedelta(days=5))
Reported by Pylint.
Line: 19
Column: 5
class TestTimedeltaIndexInsert:
def test_insert(self):
idx = TimedeltaIndex(["4day", "1day", "2day"], name="idx")
result = idx.insert(2, timedelta(days=5))
exp = TimedeltaIndex(["4day", "1day", "5day", "2day"], name="idx")
Reported by Pylint.
Line: 19
Column: 5
class TestTimedeltaIndexInsert:
def test_insert(self):
idx = TimedeltaIndex(["4day", "1day", "2day"], name="idx")
result = idx.insert(2, timedelta(days=5))
exp = TimedeltaIndex(["4day", "1day", "5day", "2day"], name="idx")
Reported by Pylint.
Line: 33
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
[Timedelta("4day"), "inserted", Timedelta("1day"), Timedelta("2day")],
name="idx",
)
assert not isinstance(result, TimedeltaIndex)
tm.assert_index_equal(result, expected)
assert result.name == expected.name
idx = timedelta_range("1day 00:00:01", periods=3, freq="s", name="idx")
Reported by Bandit.
Line: 35
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
assert not isinstance(result, TimedeltaIndex)
tm.assert_index_equal(result, expected)
assert result.name == expected.name
idx = timedelta_range("1day 00:00:01", periods=3, freq="s", name="idx")
# preserve freq
expected_0 = TimedeltaIndex(
Reported by Bandit.
pandas/tests/series/methods/test_asfreq.py
30 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytest
from pandas import (
DataFrame,
DatetimeIndex,
Series,
Reported by Pylint.
Line: 22
Column: 3
class TestAsFreq:
# TODO: de-duplicate/parametrize or move DataFrame test
def test_asfreq_ts(self):
index = period_range(freq="A", start="1/1/2001", end="12/31/2010")
ts = Series(np.random.randn(len(index)), index=index)
df = DataFrame(np.random.randn(len(index), 3), index=index)
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import numpy as np
import pytest
from pandas import (
DataFrame,
DatetimeIndex,
Series,
Reported by Pylint.
Line: 21
Column: 1
)
class TestAsFreq:
# TODO: de-duplicate/parametrize or move DataFrame test
def test_asfreq_ts(self):
index = period_range(freq="A", start="1/1/2001", end="12/31/2010")
ts = Series(np.random.randn(len(index)), index=index)
df = DataFrame(np.random.randn(len(index), 3), index=index)
Reported by Pylint.
Line: 23
Column: 5
class TestAsFreq:
# TODO: de-duplicate/parametrize or move DataFrame test
def test_asfreq_ts(self):
index = period_range(freq="A", start="1/1/2001", end="12/31/2010")
ts = Series(np.random.randn(len(index)), index=index)
df = DataFrame(np.random.randn(len(index), 3), index=index)
result = ts.asfreq("D", how="end")
Reported by Pylint.
Line: 23
Column: 5
class TestAsFreq:
# TODO: de-duplicate/parametrize or move DataFrame test
def test_asfreq_ts(self):
index = period_range(freq="A", start="1/1/2001", end="12/31/2010")
ts = Series(np.random.randn(len(index)), index=index)
df = DataFrame(np.random.randn(len(index), 3), index=index)
result = ts.asfreq("D", how="end")
Reported by Pylint.
Line: 25
Column: 9
# TODO: de-duplicate/parametrize or move DataFrame test
def test_asfreq_ts(self):
index = period_range(freq="A", start="1/1/2001", end="12/31/2010")
ts = Series(np.random.randn(len(index)), index=index)
df = DataFrame(np.random.randn(len(index), 3), index=index)
result = ts.asfreq("D", how="end")
df_result = df.asfreq("D", how="end")
exp_index = index.asfreq("D", how="end")
Reported by Pylint.
Line: 26
Column: 9
def test_asfreq_ts(self):
index = period_range(freq="A", start="1/1/2001", end="12/31/2010")
ts = Series(np.random.randn(len(index)), index=index)
df = DataFrame(np.random.randn(len(index), 3), index=index)
result = ts.asfreq("D", how="end")
df_result = df.asfreq("D", how="end")
exp_index = index.asfreq("D", how="end")
assert len(result) == len(ts)
Reported by Pylint.
Line: 31
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
result = ts.asfreq("D", how="end")
df_result = df.asfreq("D", how="end")
exp_index = index.asfreq("D", how="end")
assert len(result) == len(ts)
tm.assert_index_equal(result.index, exp_index)
tm.assert_index_equal(df_result.index, exp_index)
result = ts.asfreq("D", how="start")
assert len(result) == len(ts)
Reported by Bandit.
Line: 36
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
tm.assert_index_equal(df_result.index, exp_index)
result = ts.asfreq("D", how="start")
assert len(result) == len(ts)
tm.assert_index_equal(result.index, index.asfreq("D", how="start"))
@pytest.mark.parametrize("tz", ["US/Eastern", "dateutil/US/Eastern"])
def test_tz_aware_asfreq(self, tz):
dr = date_range("2011-12-01", "2012-07-20", freq="D", tz=tz)
Reported by Bandit.
pandas/tests/resample/test_timedelta.py
30 issues
Line: 4
Column: 1
from datetime import timedelta
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Series,
Reported by Pylint.
Line: 152
Column: 33
result = s.resample(resample_freq).min()
expected_index = timedelta_range(freq=resample_freq, start=start, end=end)
tm.assert_index_equal(result.index, expected_index)
assert result.index.freq == expected_index.freq
assert not np.isnan(result[-1])
@pytest.mark.parametrize("duplicates", [True, False])
def test_resample_with_timedelta_yields_no_empty_groups(duplicates):
Reported by Pylint.
Line: 152
Column: 33
result = s.resample(resample_freq).min()
expected_index = timedelta_range(freq=resample_freq, start=start, end=end)
tm.assert_index_equal(result.index, expected_index)
assert result.index.freq == expected_index.freq
assert not np.isnan(result[-1])
@pytest.mark.parametrize("duplicates", [True, False])
def test_resample_with_timedelta_yields_no_empty_groups(duplicates):
Reported by Pylint.
Line: 167
Column: 52
# case with non-unique columns
df.columns = ["A", "B", "A", "C"]
result = df.loc["1s":, :].resample("3s").apply(lambda x: len(x))
expected = DataFrame(
[[768] * 4] * 12 + [[528] * 4],
index=timedelta_range(start="1s", periods=13, freq="3s"),
)
Reported by Pylint.
Line: 1
Column: 1
from datetime import timedelta
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Series,
Reported by Pylint.
Line: 15
Column: 1
from pandas.core.indexes.timedeltas import timedelta_range
def test_asfreq_bug():
df = DataFrame(data=[1, 3], index=[timedelta(), timedelta(minutes=3)])
result = df.resample("1T").asfreq()
expected = DataFrame(
data=[1, np.nan, np.nan, 3],
index=timedelta_range("0 day", periods=4, freq="1T"),
Reported by Pylint.
Line: 16
Column: 5
def test_asfreq_bug():
df = DataFrame(data=[1, 3], index=[timedelta(), timedelta(minutes=3)])
result = df.resample("1T").asfreq()
expected = DataFrame(
data=[1, np.nan, np.nan, 3],
index=timedelta_range("0 day", periods=4, freq="1T"),
)
Reported by Pylint.
Line: 25
Column: 1
tm.assert_frame_equal(result, expected)
def test_resample_with_nat():
# GH 13223
index = pd.to_timedelta(["0s", pd.NaT, "2s"])
result = DataFrame({"value": [2, 3, 5]}, index).resample("1s").mean()
expected = DataFrame(
{"value": [2.5, np.nan, 5.0]},
Reported by Pylint.
Line: 36
Column: 1
tm.assert_frame_equal(result, expected)
def test_resample_as_freq_with_subperiod():
# GH 13022
index = timedelta_range("00:00:00", "00:10:00", freq="5T")
df = DataFrame(data={"value": [1, 5, 10]}, index=index)
result = df.resample("2T").asfreq()
expected_data = {"value": [1, np.nan, np.nan, np.nan, np.nan, 10]}
Reported by Pylint.
Line: 39
Column: 5
def test_resample_as_freq_with_subperiod():
# GH 13022
index = timedelta_range("00:00:00", "00:10:00", freq="5T")
df = DataFrame(data={"value": [1, 5, 10]}, index=index)
result = df.resample("2T").asfreq()
expected_data = {"value": [1, np.nan, np.nan, np.nan, np.nan, 10]}
expected = DataFrame(
data=expected_data, index=timedelta_range("00:00:00", "00:10:00", freq="2T")
)
Reported by Pylint.
pandas/tests/arrays/test_timedeltas.py
30 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import Timedelta
import pandas._testing as tm
from pandas.core.arrays import TimedeltaArray
Reported by Pylint.
Line: 46
Column: 40
def test_setitem_objects(self, obj):
# make sure we accept timedelta64 and timedelta in addition to Timedelta
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
arr[0] = obj
assert arr[0] == Timedelta(seconds=1)
@pytest.mark.parametrize(
Reported by Pylint.
Line: 46
Column: 40
def test_setitem_objects(self, obj):
# make sure we accept timedelta64 and timedelta in addition to Timedelta
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
arr[0] = obj
assert arr[0] == Timedelta(seconds=1)
@pytest.mark.parametrize(
Reported by Pylint.
Line: 105
Column: 40
def test_neg_freq(self):
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
expected = TimedeltaArray(-tdi._data, freq=-tdi.freq)
result = -arr
tm.assert_timedelta_array_equal(result, expected)
Reported by Pylint.
Line: 105
Column: 40
def test_neg_freq(self):
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
expected = TimedeltaArray(-tdi._data, freq=-tdi.freq)
result = -arr
tm.assert_timedelta_array_equal(result, expected)
Reported by Pylint.
Line: 107
Column: 53
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
expected = TimedeltaArray(-tdi._data, freq=-tdi.freq)
result = -arr
tm.assert_timedelta_array_equal(result, expected)
Reported by Pylint.
Line: 107
Column: 53
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
expected = TimedeltaArray(-tdi._data, freq=-tdi.freq)
result = -arr
tm.assert_timedelta_array_equal(result, expected)
Reported by Pylint.
Line: 13
Column: 15
class TestTimedeltaArray:
@pytest.mark.parametrize("dtype", [int, np.int32, np.int64, "uint32", "uint64"])
def test_astype_int(self, dtype):
arr = TimedeltaArray._from_sequence([Timedelta("1H"), Timedelta("2H")])
with tm.assert_produces_warning(FutureWarning):
# astype(int..) deprecated
result = arr.astype(dtype)
if np.dtype(dtype).kind == "u":
Reported by Pylint.
Line: 107
Column: 36
tdi = pd.timedelta_range("2 Days", periods=4, freq="H")
arr = TimedeltaArray(tdi, freq=tdi.freq)
expected = TimedeltaArray(-tdi._data, freq=-tdi.freq)
result = -arr
tm.assert_timedelta_array_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import Timedelta
import pandas._testing as tm
from pandas.core.arrays import TimedeltaArray
Reported by Pylint.
pandas/tests/indexes/multi/test_lexsort.py
30 issues
Line: 12
Column: 16
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]]
)
assert index._is_lexsorted()
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2, 1]]
)
assert not index._is_lexsorted()
Reported by Pylint.
Line: 17
Column: 20
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2, 1]]
)
assert not index._is_lexsorted()
index = MultiIndex(
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]]
)
assert not index._is_lexsorted()
Reported by Pylint.
Line: 22
Column: 20
index = MultiIndex(
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]]
)
assert not index._is_lexsorted()
assert index._lexsort_depth == 0
def test_is_lexsorted_deprecation(self):
# GH 32259
with tm.assert_produces_warning():
Reported by Pylint.
Line: 23
Column: 16
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]]
)
assert not index._is_lexsorted()
assert index._lexsort_depth == 0
def test_is_lexsorted_deprecation(self):
# GH 32259
with tm.assert_produces_warning():
MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).is_lexsorted()
Reported by Pylint.
Line: 23
Column: 16
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]]
)
assert not index._is_lexsorted()
assert index._lexsort_depth == 0
def test_is_lexsorted_deprecation(self):
# GH 32259
with tm.assert_produces_warning():
MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).is_lexsorted()
Reported by Pylint.
Line: 42
Column: 16
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]], sortorder=2
)
assert index._lexsort_depth == 2
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2, 1]], sortorder=1
)
assert index._lexsort_depth == 1
Reported by Pylint.
Line: 42
Column: 16
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]], sortorder=2
)
assert index._lexsort_depth == 2
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2, 1]], sortorder=1
)
assert index._lexsort_depth == 1
Reported by Pylint.
Line: 47
Column: 16
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2, 1]], sortorder=1
)
assert index._lexsort_depth == 1
index = MultiIndex(
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]], sortorder=0
)
assert index._lexsort_depth == 0
Reported by Pylint.
Line: 47
Column: 16
index = MultiIndex(
levels=levels, codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2, 1]], sortorder=1
)
assert index._lexsort_depth == 1
index = MultiIndex(
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]], sortorder=0
)
assert index._lexsort_depth == 0
Reported by Pylint.
Line: 52
Column: 16
index = MultiIndex(
levels=levels, codes=[[0, 0, 1, 0, 1, 1], [0, 1, 0, 2, 2, 1]], sortorder=0
)
assert index._lexsort_depth == 0
def test_lexsort_depth_deprecation(self):
# GH 32259
with tm.assert_produces_warning():
MultiIndex.from_arrays([["a", "b", "c"], ["d", "f", "e"]]).lexsort_depth
Reported by Pylint.
pandas/tests/frame/test_logical_ops.py
30 issues
Line: 5
Column: 1
import re
import numpy as np
import pytest
from pandas import (
CategoricalIndex,
DataFrame,
Interval,
Reported by Pylint.
Line: 106
Column: 13
df2 = DataFrame(True, index=[1], columns=["A"])
msg = re.escape("unsupported operand type(s) for |: 'float' and 'bool'")
with pytest.raises(TypeError, match=msg):
df1 | df2
df1 = DataFrame("foo", index=[1], columns=["A"])
df2 = DataFrame(True, index=[1], columns=["A"])
msg = re.escape("unsupported operand type(s) for |: 'str' and 'bool'")
with pytest.raises(TypeError, match=msg):
Reported by Pylint.
Line: 112
Column: 13
df2 = DataFrame(True, index=[1], columns=["A"])
msg = re.escape("unsupported operand type(s) for |: 'str' and 'bool'")
with pytest.raises(TypeError, match=msg):
df1 | df2
def test_logical_operators(self):
def _check_bin_op(op):
result = op(df1, df2)
expected = DataFrame(
Reported by Pylint.
Line: 152
Column: 3
_check_bin_op(operator.or_)
_check_bin_op(operator.xor)
_check_unary_op(operator.inv) # TODO: belongs elsewhere
def test_logical_with_nas(self):
d = DataFrame({"a": [np.nan, False], "b": [True, True]})
# GH4947
Reported by Pylint.
Line: 1
Column: 1
import operator
import re
import numpy as np
import pytest
from pandas import (
CategoricalIndex,
DataFrame,
Reported by Pylint.
Line: 17
Column: 1
import pandas._testing as tm
class TestDataFrameLogicalOperators:
# &, |, ^
@pytest.mark.parametrize(
"left, right, op, expected",
[
Reported by Pylint.
Line: 46
Column: 5
[True, False, np.nan],
operator.or_,
[True, False, True],
),
],
)
def test_logical_operators_nans(self, left, right, op, expected, frame_or_series):
# GH#13896
result = op(frame_or_series(left), frame_or_series(right))
Reported by Pylint.
Line: 46
Column: 5
[True, False, np.nan],
operator.or_,
[True, False, True],
),
],
)
def test_logical_operators_nans(self, left, right, op, expected, frame_or_series):
# GH#13896
result = op(frame_or_series(left), frame_or_series(right))
Reported by Pylint.
Line: 46
Column: 5
[True, False, np.nan],
operator.or_,
[True, False, True],
),
],
)
def test_logical_operators_nans(self, left, right, op, expected, frame_or_series):
# GH#13896
result = op(frame_or_series(left), frame_or_series(right))
Reported by Pylint.
Line: 46
Column: 5
[True, False, np.nan],
operator.or_,
[True, False, True],
),
],
)
def test_logical_operators_nans(self, left, right, op, expected, frame_or_series):
# GH#13896
result = op(frame_or_series(left), frame_or_series(right))
Reported by Pylint.
pandas/tests/frame/indexing/test_mask.py
29 issues
Line: 17
Column: 1
import pandas._testing as tm
class TestDataFrameMask:
def test_mask(self):
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rs = df.where(cond, np.nan)
Reported by Pylint.
Line: 18
Column: 5
class TestDataFrameMask:
def test_mask(self):
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rs = df.where(cond, np.nan)
tm.assert_frame_equal(rs, df.mask(df <= 0))
Reported by Pylint.
Line: 18
Column: 5
class TestDataFrameMask:
def test_mask(self):
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rs = df.where(cond, np.nan)
tm.assert_frame_equal(rs, df.mask(df <= 0))
Reported by Pylint.
Line: 19
Column: 9
class TestDataFrameMask:
def test_mask(self):
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rs = df.where(cond, np.nan)
tm.assert_frame_equal(rs, df.mask(df <= 0))
tm.assert_frame_equal(rs, df.mask(~cond))
Reported by Pylint.
Line: 22
Column: 9
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rs = df.where(cond, np.nan)
tm.assert_frame_equal(rs, df.mask(df <= 0))
tm.assert_frame_equal(rs, df.mask(~cond))
other = DataFrame(np.random.randn(5, 3))
rs = df.where(cond, other)
Reported by Pylint.
Line: 27
Column: 9
tm.assert_frame_equal(rs, df.mask(~cond))
other = DataFrame(np.random.randn(5, 3))
rs = df.where(cond, other)
tm.assert_frame_equal(rs, df.mask(df <= 0, other))
tm.assert_frame_equal(rs, df.mask(~cond, other))
# see GH#21891
df = DataFrame([1, 2])
Reported by Pylint.
Line: 32
Column: 9
tm.assert_frame_equal(rs, df.mask(~cond, other))
# see GH#21891
df = DataFrame([1, 2])
res = df.mask([[True], [False]])
exp = DataFrame([np.nan, 2])
tm.assert_frame_equal(res, exp)
Reported by Pylint.
Line: 38
Column: 5
exp = DataFrame([np.nan, 2])
tm.assert_frame_equal(res, exp)
def test_mask_inplace(self):
# GH#8801
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rdf = df.copy()
Reported by Pylint.
Line: 38
Column: 5
exp = DataFrame([np.nan, 2])
tm.assert_frame_equal(res, exp)
def test_mask_inplace(self):
# GH#8801
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rdf = df.copy()
Reported by Pylint.
Line: 40
Column: 9
def test_mask_inplace(self):
# GH#8801
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
rdf = df.copy()
return_value = rdf.where(cond, inplace=True)
Reported by Pylint.
pandas/core/util/hashing.py
29 issues
Line: 17
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._libs.hashing import hash_object_array
from pandas._typing import ArrayLike
from pandas.core.dtypes.common import (
is_categorical_dtype,
Reported by Pylint.
Line: 18
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._libs.hashing import hash_object_array
from pandas._typing import ArrayLike
from pandas.core.dtypes.common import (
is_categorical_dtype,
is_list_like,
Reported by Pylint.
Line: 18
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._libs.hashing import hash_object_array
from pandas._typing import ArrayLike
from pandas.core.dtypes.common import (
is_categorical_dtype,
is_list_like,
Reported by Pylint.
Line: 73
Column: 12
out ^= a
out *= mult
mult += np.uint64(82520 + inverse_i + inverse_i)
assert i + 1 == num_items, "Fed in wrong num_items"
out += np.uint64(97531)
return out
def hash_pandas_object(
Reported by Pylint.
Line: 114
Column: 24
return Series(hash_tuples(obj, encoding, hash_key), dtype="uint64", copy=False)
elif isinstance(obj, ABCIndex):
h = hash_array(obj._values, encoding, hash_key, categorize).astype(
"uint64", copy=False
)
ser = Series(h, index=obj, dtype="uint64", copy=False)
elif isinstance(obj, ABCSeries):
Reported by Pylint.
Line: 120
Column: 24
ser = Series(h, index=obj, dtype="uint64", copy=False)
elif isinstance(obj, ABCSeries):
h = hash_array(obj._values, encoding, hash_key, categorize).astype(
"uint64", copy=False
)
if index:
index_iter = (
hash_pandas_object(
Reported by Pylint.
Line: 125
Column: 17
)
if index:
index_iter = (
hash_pandas_object(
obj.index,
index=False,
encoding=encoding,
hash_key=hash_key,
categorize=categorize,
Reported by Pylint.
Line: 141
Column: 24
elif isinstance(obj, ABCDataFrame):
hashes = (
hash_array(series._values, encoding, hash_key, categorize)
for _, series in obj.items()
)
num_items = len(obj.columns)
if index:
index_hash_generator = (
Reported by Pylint.
Line: 147
Column: 17
num_items = len(obj.columns)
if index:
index_hash_generator = (
hash_pandas_object(
obj.index,
index=False,
encoding=encoding,
hash_key=hash_key,
categorize=categorize,
Reported by Pylint.
Line: 232
Column: 25
ndarray[np.uint64] of hashed values, same size as len(c)
"""
# Convert ExtensionArrays to ndarrays
values = np.asarray(cat.categories._values)
hashed = hash_array(values, encoding, hash_key, categorize=False)
# we have uint64, as we don't directly support missing values
# we don't want to use take_nd which will coerce to float
# instead, directly construct the result with a
Reported by Pylint.