The following issues were found
pandas/tests/plotting/frame/test_frame_color.py
225 issues
Line: 6
Column: 1
import warnings
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import DataFrame
Reported by Pylint.
Line: 130
Column: 24
# Test str -> colormap functionality
ax = df.plot.bar(colormap="jet")
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)]
self._check_colors(ax.patches[::5], facecolors=rgba_colors)
tm.close()
# Test colormap functionality
ax = df.plot.bar(colormap=cm.jet)
Reported by Pylint.
Line: 135
Column: 35
tm.close()
# Test colormap functionality
ax = df.plot.bar(colormap=cm.jet)
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)]
self._check_colors(ax.patches[::5], facecolors=rgba_colors)
tm.close()
ax = df.loc[:, [0]].plot.bar(color="DodgerBlue")
Reported by Pylint.
Line: 136
Column: 24
# Test colormap functionality
ax = df.plot.bar(colormap=cm.jet)
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)]
self._check_colors(ax.patches[::5], facecolors=rgba_colors)
tm.close()
ax = df.loc[:, [0]].plot.bar(color="DodgerBlue")
self._check_colors([ax.patches[0]], facecolors=["DodgerBlue"])
Reported by Pylint.
Line: 231
Column: 46
with pytest.raises(TypeError, match="Specify exactly one of `c` and `color`"):
df.plot.scatter(x="a", y="b", c="c", color="green")
default_colors = self._unpack_cycler(self.plt.rcParams)
ax = df.plot.scatter(x="a", y="b", c="c")
tm.assert_numpy_array_equal(
ax.collections[0].get_facecolor()[0],
np.array(self.colorconverter.to_rgba(default_colors[0])),
Reported by Pylint.
Line: 236
Column: 22
ax = df.plot.scatter(x="a", y="b", c="c")
tm.assert_numpy_array_equal(
ax.collections[0].get_facecolor()[0],
np.array(self.colorconverter.to_rgba(default_colors[0])),
)
ax = df.plot.scatter(x="a", y="b", color="white")
tm.assert_numpy_array_equal(
ax.collections[0].get_facecolor()[0],
Reported by Pylint.
Line: 279
Column: 24
tm.close()
ax = df.plot(colormap="jet")
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))]
self._check_colors(ax.get_lines(), linecolors=rgba_colors)
tm.close()
ax = df.plot(colormap=cm.jet)
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))]
Reported by Pylint.
Line: 283
Column: 31
self._check_colors(ax.get_lines(), linecolors=rgba_colors)
tm.close()
ax = df.plot(colormap=cm.jet)
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))]
self._check_colors(ax.get_lines(), linecolors=rgba_colors)
tm.close()
# make color a list if plotting one column frame
Reported by Pylint.
Line: 284
Column: 24
tm.close()
ax = df.plot(colormap=cm.jet)
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))]
self._check_colors(ax.get_lines(), linecolors=rgba_colors)
tm.close()
# make color a list if plotting one column frame
# handles cases like df.plot(color='DodgerBlue')
Reported by Pylint.
Line: 312
Column: 46
# GH 9894
from matplotlib import cm
default_colors = self._unpack_cycler(self.plt.rcParams)
df = DataFrame(np.random.randn(5, 5))
axes = df.plot(subplots=True)
for ax, c in zip(axes, list(default_colors)):
Reported by Pylint.
pandas/tests/frame/methods/test_reindex.py
223 issues
Line: 9
Column: 1
from itertools import permutations
import numpy as np
import pytest
import pandas as pd
from pandas import (
Categorical,
CategoricalIndex,
Reported by Pylint.
Line: 52
Column: 37
)
result = df.set_index(new_index)
assert result.index.freq == index.freq
def test_set_reset_index_intervalindex(self):
df = DataFrame({"A": range(10)})
ser = pd.cut(df.A, 5)
Reported by Pylint.
Line: 52
Column: 37
)
result = df.set_index(new_index)
assert result.index.freq == index.freq
def test_set_reset_index_intervalindex(self):
df = DataFrame({"A": range(10)})
ser = pd.cut(df.A, 5)
Reported by Pylint.
Line: 94
Column: 56
np.random.shuffle(cols)
result = df.reindex(columns=cols, copy=True)
assert not np.shares_memory(result[0]._values, df[0]._values)
# pass both columns and index
result2 = df.reindex(columns=cols, index=df.index, copy=True)
assert not np.shares_memory(result2[0]._values, df[0]._values)
Reported by Pylint.
Line: 94
Column: 37
np.random.shuffle(cols)
result = df.reindex(columns=cols, copy=True)
assert not np.shares_memory(result[0]._values, df[0]._values)
# pass both columns and index
result2 = df.reindex(columns=cols, index=df.index, copy=True)
assert not np.shares_memory(result2[0]._values, df[0]._values)
Reported by Pylint.
Line: 98
Column: 57
# pass both columns and index
result2 = df.reindex(columns=cols, index=df.index, copy=True)
assert not np.shares_memory(result2[0]._values, df[0]._values)
def test_reindex_date_fill_value(self):
# passing date to dt64 is deprecated
arr = date_range("2016-01-01", periods=6).values.reshape(3, 2)
df = DataFrame(arr, columns=["A", "B"], index=range(3))
Reported by Pylint.
Line: 98
Column: 37
# pass both columns and index
result2 = df.reindex(columns=cols, index=df.index, copy=True)
assert not np.shares_memory(result2[0]._values, df[0]._values)
def test_reindex_date_fill_value(self):
# passing date to dt64 is deprecated
arr = date_range("2016-01-01", periods=6).values.reshape(3, 2)
df = DataFrame(arr, columns=["A", "B"], index=range(3))
Reported by Pylint.
Line: 485
Column: 20
# pass non-Index
newFrame = float_frame.reindex(list(datetime_series.index))
expected = datetime_series.index._with_freq(None)
tm.assert_index_equal(newFrame.index, expected)
# copy with no axes
result = float_frame.reindex()
tm.assert_frame_equal(result, float_frame)
Reported by Pylint.
Line: 1
Column: 1
from datetime import (
datetime,
timedelta,
)
import inspect
from itertools import permutations
import numpy as np
import pytest
Reported by Pylint.
Line: 1
Column: 1
from datetime import (
datetime,
timedelta,
)
import inspect
from itertools import permutations
import numpy as np
import pytest
Reported by Pylint.
pandas/tests/indexes/numeric/test_numeric.py
223 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas._libs.tslibs import Timestamp
import pandas as pd
from pandas import (
Float64Index,
Index,
Reported by Pylint.
Line: 33
Column: 16
@pytest.fixture
def simple_index(self, dtype):
values = np.arange(5, dtype=dtype)
return self._index_cls(values)
@pytest.fixture(
params=[
[1.5, 2, 3, 4, 5],
[0.0, 2.5, 5.0, 7.5, 10.0],
Reported by Pylint.
Line: 45
Column: 16
ids=["mixed", "float", "mixed_dec", "float_dec"],
)
def index(self, request, dtype):
return self._index_cls(request.param, dtype=dtype)
@pytest.fixture
def mixed_index(self, dtype):
return self._index_cls([1.5, 2, 3, 4, 5], dtype=dtype)
Reported by Pylint.
Line: 49
Column: 16
@pytest.fixture
def mixed_index(self, dtype):
return self._index_cls([1.5, 2, 3, 4, 5], dtype=dtype)
@pytest.fixture
def float_index(self, dtype):
return self._index_cls([0.0, 2.5, 5.0, 7.5, 10.0], dtype=dtype)
Reported by Pylint.
Line: 53
Column: 16
@pytest.fixture
def float_index(self, dtype):
return self._index_cls([0.0, 2.5, 5.0, 7.5, 10.0], dtype=dtype)
def test_repr_roundtrip(self, index):
tm.assert_index_equal(eval(repr(index)), index, exact=True)
def check_is_index(self, idx):
Reported by Pylint.
Line: 60
Column: 36
def check_is_index(self, idx):
assert isinstance(idx, Index)
assert not isinstance(idx, self._index_cls)
def check_coerce(self, a, b, is_float_index=True):
assert a.equals(b)
tm.assert_index_equal(a, b, exact=False)
if is_float_index:
Reported by Pylint.
Line: 66
Column: 34
assert a.equals(b)
tm.assert_index_equal(a, b, exact=False)
if is_float_index:
assert isinstance(b, self._index_cls)
else:
self.check_is_index(b)
def test_constructor(self, dtype):
index_cls = self._index_cls
Reported by Pylint.
Line: 71
Column: 21
self.check_is_index(b)
def test_constructor(self, dtype):
index_cls = self._index_cls
# explicit construction
index = index_cls([1, 2, 3, 4, 5], dtype=dtype)
assert isinstance(index, index_cls)
Reported by Pylint.
Line: 110
Column: 21
assert pd.isna(result.values).all()
def test_constructor_invalid(self):
index_cls = self._index_cls
cls_name = index_cls.__name__
# invalid
msg = (
rf"{cls_name}\(\.\.\.\) must be called with a collection of "
Reported by Pylint.
Line: 167
Column: 21
tm.assert_index_equal(idx, Index([1, 2, 3.5]), exact=True)
def test_equals_numeric(self):
index_cls = self._index_cls
idx = index_cls([1.0, 2.0])
assert idx.equals(idx)
assert idx.identical(idx)
Reported by Pylint.
pandas/tests/indexes/multi/test_indexing.py
214 issues
Line: 5
Column: 1
import re
import numpy as np
import pytest
from pandas.errors import (
InvalidIndexError,
PerformanceWarning,
)
Reported by Pylint.
Line: 167
Column: 14
idx1 = index[:5]
idx2 = index[[1, 3, 5]]
r1 = idx1.get_indexer(idx2)
tm.assert_almost_equal(r1, np.array([1, 3, -1], dtype=np.intp))
r1 = idx2.get_indexer(idx1, method="pad")
e1 = np.array([-1, 0, 0, 1, 1], dtype=np.intp)
tm.assert_almost_equal(r1, e1)
Reported by Pylint.
Line: 170
Column: 14
r1 = idx1.get_indexer(idx2)
tm.assert_almost_equal(r1, np.array([1, 3, -1], dtype=np.intp))
r1 = idx2.get_indexer(idx1, method="pad")
e1 = np.array([-1, 0, 0, 1, 1], dtype=np.intp)
tm.assert_almost_equal(r1, e1)
r2 = idx2.get_indexer(idx1[::-1], method="pad")
tm.assert_almost_equal(r2, e1[::-1])
Reported by Pylint.
Line: 174
Column: 14
e1 = np.array([-1, 0, 0, 1, 1], dtype=np.intp)
tm.assert_almost_equal(r1, e1)
r2 = idx2.get_indexer(idx1[::-1], method="pad")
tm.assert_almost_equal(r2, e1[::-1])
rffill1 = idx2.get_indexer(idx1, method="ffill")
tm.assert_almost_equal(r1, rffill1)
Reported by Pylint.
Line: 177
Column: 19
r2 = idx2.get_indexer(idx1[::-1], method="pad")
tm.assert_almost_equal(r2, e1[::-1])
rffill1 = idx2.get_indexer(idx1, method="ffill")
tm.assert_almost_equal(r1, rffill1)
r1 = idx2.get_indexer(idx1, method="backfill")
e1 = np.array([0, 0, 1, 1, 2], dtype=np.intp)
tm.assert_almost_equal(r1, e1)
Reported by Pylint.
Line: 180
Column: 14
rffill1 = idx2.get_indexer(idx1, method="ffill")
tm.assert_almost_equal(r1, rffill1)
r1 = idx2.get_indexer(idx1, method="backfill")
e1 = np.array([0, 0, 1, 1, 2], dtype=np.intp)
tm.assert_almost_equal(r1, e1)
r2 = idx2.get_indexer(idx1[::-1], method="backfill")
tm.assert_almost_equal(r2, e1[::-1])
Reported by Pylint.
Line: 184
Column: 14
e1 = np.array([0, 0, 1, 1, 2], dtype=np.intp)
tm.assert_almost_equal(r1, e1)
r2 = idx2.get_indexer(idx1[::-1], method="backfill")
tm.assert_almost_equal(r2, e1[::-1])
rbfill1 = idx2.get_indexer(idx1, method="bfill")
tm.assert_almost_equal(r1, rbfill1)
Reported by Pylint.
Line: 187
Column: 19
r2 = idx2.get_indexer(idx1[::-1], method="backfill")
tm.assert_almost_equal(r2, e1[::-1])
rbfill1 = idx2.get_indexer(idx1, method="bfill")
tm.assert_almost_equal(r1, rbfill1)
# pass non-MultiIndex
r1 = idx1.get_indexer(idx2.values)
rexp1 = idx1.get_indexer(idx2)
Reported by Pylint.
Line: 191
Column: 14
tm.assert_almost_equal(r1, rbfill1)
# pass non-MultiIndex
r1 = idx1.get_indexer(idx2.values)
rexp1 = idx1.get_indexer(idx2)
tm.assert_almost_equal(r1, rexp1)
r1 = idx1.get_indexer([1, 2, 3])
assert (r1 == [-1, -1, -1]).all()
Reported by Pylint.
Line: 191
Column: 31
tm.assert_almost_equal(r1, rbfill1)
# pass non-MultiIndex
r1 = idx1.get_indexer(idx2.values)
rexp1 = idx1.get_indexer(idx2)
tm.assert_almost_equal(r1, rexp1)
r1 = idx1.get_indexer([1, 2, 3])
assert (r1 == [-1, -1, -1]).all()
Reported by Pylint.
pandas/tests/arrays/categorical/test_constructors.py
213 issues
Line: 7
Column: 1
)
import numpy as np
import pytest
from pandas.compat import (
IS64,
is_platform_windows,
)
Reported by Pylint.
Line: 364
Column: 15
def test_constructor_from_index_series_datetimetz(self):
idx = date_range("2015-01-01 10:00", freq="D", periods=3, tz="US/Eastern")
idx = idx._with_freq(None) # freq not preserved in result.categories
result = Categorical(idx)
tm.assert_index_equal(result.categories, idx)
result = Categorical(Series(idx))
tm.assert_index_equal(result.categories, idx)
Reported by Pylint.
Line: 364
Column: 15
def test_constructor_from_index_series_datetimetz(self):
idx = date_range("2015-01-01 10:00", freq="D", periods=3, tz="US/Eastern")
idx = idx._with_freq(None) # freq not preserved in result.categories
result = Categorical(idx)
tm.assert_index_equal(result.categories, idx)
result = Categorical(Series(idx))
tm.assert_index_equal(result.categories, idx)
Reported by Pylint.
Line: 381
Column: 15
def test_constructor_from_index_series_timedelta(self):
idx = timedelta_range("1 days", freq="D", periods=3)
idx = idx._with_freq(None) # freq not preserved in result.categories
result = Categorical(idx)
tm.assert_index_equal(result.categories, idx)
result = Categorical(Series(idx))
tm.assert_index_equal(result.categories, idx)
Reported by Pylint.
Line: 381
Column: 15
def test_constructor_from_index_series_timedelta(self):
idx = timedelta_range("1 days", freq="D", periods=3)
idx = idx._with_freq(None) # freq not preserved in result.categories
result = Categorical(idx)
tm.assert_index_equal(result.categories, idx)
result = Categorical(Series(idx))
tm.assert_index_equal(result.categories, idx)
Reported by Pylint.
Line: 238
Column: 13
# - when the first is an integer dtype and the second is not
# - when the resulting codes are all -1/NaN
with tm.assert_produces_warning(None):
c_old = Categorical([0, 1, 2, 0, 1, 2], categories=["a", "b", "c"])
with tm.assert_produces_warning(None):
c_old = Categorical([0, 1, 2, 0, 1, 2], categories=[3, 4, 5]) # noqa
# the next one are from the old docs
Reported by Pylint.
Line: 245
Column: 13
# the next one are from the old docs
with tm.assert_produces_warning(None):
c_old2 = Categorical([0, 1, 2, 0, 1, 2], [1, 2, 3]) # noqa
cat = Categorical([1, 2], categories=[1, 2, 3])
# this is a legitimate constructor
with tm.assert_produces_warning(None):
c = Categorical( # noqa
Reported by Pylint.
Line: 250
Column: 13
# this is a legitimate constructor
with tm.assert_produces_warning(None):
c = Categorical( # noqa
np.array([], dtype="int64"), categories=[3, 2, 1], ordered=True
)
def test_constructor_with_existing_categories(self):
# GH25318: constructing with pd.Series used to bogusly skip recoding
Reported by Pylint.
Line: 341
Column: 9
c = Categorical(s)
expected = type(dtl)(s)
expected._data.freq = None
tm.assert_index_equal(c.categories, expected)
tm.assert_numpy_array_equal(c.codes, np.arange(5, dtype="int8"))
# with NaT
Reported by Pylint.
Line: 352
Column: 9
c = Categorical(s2)
expected = type(dtl)(s2.dropna())
expected._data.freq = None
tm.assert_index_equal(c.categories, expected)
exp = np.array([0, 1, 2, 3, -1], dtype=np.int8)
tm.assert_numpy_array_equal(c.codes, exp)
Reported by Pylint.
pandas/tests/indexes/common.py
206 issues
Line: 7
Column: 1
import gc
import numpy as np
import pytest
from pandas._libs import iNaT
from pandas._libs.tslibs import Timestamp
from pandas.core.dtypes.common import (
Reported by Pylint.
Line: 799
Column: 21
"""
def test_constructor_unwraps_index(self, dtype):
index_cls = self._index_cls
idx = Index([1, 2], dtype=dtype)
result = index_cls(idx)
expected = np.array([1, 2], dtype=idx.dtype)
tm.assert_numpy_array_equal(result._data, expected)
Reported by Pylint.
Line: 841
Column: 21
def test_arithmetic_explicit_conversions(self):
# GH 8608
# add/sub are overridden explicitly for Float/Int Index
index_cls = self._index_cls
if index_cls is RangeIndex:
idx = RangeIndex(5)
else:
idx = index_cls(np.arange(5, dtype="int64"))
Reported by Pylint.
Line: 871
Column: 13
dtype = invalid_dtype
msg = fr"Incorrect `dtype` passed: expected \w+(?: \w+)?, received {dtype}"
with pytest.raises(ValueError, match=msg):
self._index_cls([1, 2, 3], dtype=dtype)
Reported by Pylint.
Line: 36
Column: 1
TimedeltaIndex,
isna,
)
from pandas import UInt64Index # noqa:F401
import pandas._testing as tm
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
class Base:
Reported by Pylint.
Line: 174
Column: 20
if type(idx) is Index:
return
typ = type(idx._data).__name__
cls = type(idx).__name__
lmsg = "|".join(
[
rf"unsupported operand type\(s\) for \*: '{typ}' and 'int'",
"cannot perform (__mul__|__truediv__|__floordiv__) with "
Reported by Pylint.
Line: 184
Column: 13
]
)
with pytest.raises(TypeError, match=lmsg):
idx * 1
rmsg = "|".join(
[
rf"unsupported operand type\(s\) for \*: 'int' and '{typ}'",
"cannot perform (__rmul__|__rtruediv__|__rfloordiv__) with "
f"this index type: ({cls}|{typ})",
Reported by Pylint.
Line: 193
Column: 13
]
)
with pytest.raises(TypeError, match=rmsg):
1 * idx
div_err = lmsg.replace("*", "/")
with pytest.raises(TypeError, match=div_err):
idx / 1
div_err = rmsg.replace("*", "/")
Reported by Pylint.
Line: 197
Column: 13
div_err = lmsg.replace("*", "/")
with pytest.raises(TypeError, match=div_err):
idx / 1
div_err = rmsg.replace("*", "/")
with pytest.raises(TypeError, match=div_err):
1 / idx
floordiv_err = lmsg.replace("*", "//")
Reported by Pylint.
Line: 200
Column: 13
idx / 1
div_err = rmsg.replace("*", "/")
with pytest.raises(TypeError, match=div_err):
1 / idx
floordiv_err = lmsg.replace("*", "//")
with pytest.raises(TypeError, match=floordiv_err):
idx // 1
floordiv_err = rmsg.replace("*", "//")
Reported by Pylint.
pandas/tests/groupby/aggregate/test_aggregate.py
200 issues
Line: 10
Column: 1
import re
import numpy as np
import pytest
from pandas.errors import PerformanceWarning
from pandas.core.dtypes.common import is_integer_dtype
Reported by Pylint.
Line: 244
Column: 5
exp = Series(np.array([bar] * K), index=list("BCD"), name="bar")
tm.assert_almost_equal(result.xs("bar"), exp)
def aggfun(ser):
return ser.size
result = DataFrame().groupby(df.A).agg(aggfun)
assert isinstance(result, DataFrame)
assert len(result) == 0
Reported by Pylint.
Line: 59
Column: 3
def test_agg_ser_multi_key(df):
# TODO(wesm): unused
ser = df.C # noqa
f = lambda x: x.sum()
results = df.C.groupby([df.A, df.B]).aggregate(f)
expected = df.groupby(["A", "B"]).sum()["C"]
Reported by Pylint.
Line: 60
Column: 5
def test_agg_ser_multi_key(df):
# TODO(wesm): unused
ser = df.C # noqa
f = lambda x: x.sum()
results = df.C.groupby([df.A, df.B]).aggregate(f)
expected = df.groupby(["A", "B"]).sum()["C"]
tm.assert_series_equal(results, expected)
Reported by Pylint.
Line: 488
Column: 56
@pytest.mark.parametrize("input", [True, 1, 1.0])
@pytest.mark.parametrize("dtype", [bool, int, float])
@pytest.mark.parametrize("method", ["apply", "aggregate", "transform"])
def test_callable_result_dtype_series(keys, agg_index, input, dtype, method):
# GH 21240
df = DataFrame({"a": [1], "b": [2], "c": [input]})
op = getattr(df.groupby(keys)["c"], method)
result = op(lambda x: x.astype(dtype).iloc[0])
expected_index = pd.RangeIndex(0, 1) if method == "transform" else agg_index
Reported by Pylint.
Line: 775
Column: 26
[5.5, 7.5],
),
(
(("y", "A"), lambda x: max(x)),
(("y", "A"), lambda x: 1),
(("y", "B"), "mean"),
[1, 3],
[1, 1],
[5.5, 7.5],
Reported by Pylint.
Line: 900
Column: 34
@pytest.mark.parametrize(
"func", [lambda s: s.mean(), lambda s: np.mean(s), lambda s: np.nanmean(s)]
)
def test_multiindex_custom_func(func):
# GH 31777
data = [[1, 4, 2], [5, 7, 1]]
df = DataFrame(
Reported by Pylint.
Line: 900
Column: 56
@pytest.mark.parametrize(
"func", [lambda s: s.mean(), lambda s: np.mean(s), lambda s: np.nanmean(s)]
)
def test_multiindex_custom_func(func):
# GH 31777
data = [[1, 4, 2], [5, 7, 1]]
df = DataFrame(
Reported by Pylint.
Line: 1089
Column: 37
height_sqr_min=("height", lambda x: np.min(x ** 2)),
height_max=("height", "max"),
weight_max=("weight", "max"),
height_max_2=("height", lambda x: np.max(x)),
weight_min=("weight", lambda x: np.min(x)),
)
tm.assert_frame_equal(result1, expected)
# check pd.NamedAgg case
Reported by Pylint.
Line: 1090
Column: 35
height_max=("height", "max"),
weight_max=("weight", "max"),
height_max_2=("height", lambda x: np.max(x)),
weight_min=("weight", lambda x: np.min(x)),
)
tm.assert_frame_equal(result1, expected)
# check pd.NamedAgg case
result2 = df.groupby(by="kind").agg(
Reported by Pylint.
pandas/tests/apply/test_frame_apply.py
199 issues
Line: 5
Column: 1
import warnings
import numpy as np
import pytest
from pandas.core.dtypes.dtypes import CategoricalDtype
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 1325
Column: 12
original = index.copy()
df = DataFrame(1, index=index, columns=range(num_cols))
df.apply(lambda x: x)
assert index.freq == original.freq
def test_apply_datetime_tz_issue():
# GH 29052
Reported by Pylint.
Line: 278
Column: 28
def _checkit(axis=0, raw=False):
result = df.apply(f, axis=axis, raw=raw)
if is_reduction:
agg_axis = df._get_agg_axis(axis)
assert isinstance(result, Series)
assert result.index is agg_axis
else:
assert isinstance(result, DataFrame)
Reported by Pylint.
Line: 442
Column: 14
}
)
result = expected.apply(lambda x: x, axis=1)._convert(datetime=True)
tm.assert_frame_equal(result, expected)
def test_apply_attach_name(float_frame):
result = float_frame.apply(lambda x: x.name)
Reported by Pylint.
Line: 472
Column: 28
tm.assert_series_equal(result, expected)
def test_apply_multi_index(float_frame):
index = MultiIndex.from_arrays([["a", "a", "b"], ["c", "d", "d"]])
s = DataFrame([[1, 2], [3, 4], [5, 6]], index=index, columns=["col1", "col2"])
result = s.apply(lambda x: Series({"min": min(x), "max": max(x)}), 1)
expected = DataFrame([[1, 2], [3, 4], [5, 6]], index=index, columns=["min", "max"])
tm.assert_frame_equal(result, expected, check_like=True)
Reported by Pylint.
Line: 900
Column: 13
}
)
def fun(x):
return (1, 2)
result = df.apply(fun, axis=1)
expected = Series([(1, 2) for t in df.itertuples()])
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 981
Column: 6
@pytest.mark.parametrize(
"box",
[lambda x: list(x), lambda x: tuple(x), lambda x: np.array(x, dtype="int64")],
ids=["list", "tuple", "array"],
)
def test_consistency_for_boxed(box, int_frame_const_col):
# passing an array or list should not affect the output shape
df = int_frame_const_col
Reported by Pylint.
Line: 981
Column: 25
@pytest.mark.parametrize(
"box",
[lambda x: list(x), lambda x: tuple(x), lambda x: np.array(x, dtype="int64")],
ids=["list", "tuple", "array"],
)
def test_consistency_for_boxed(box, int_frame_const_col):
# passing an array or list should not affect the output shape
df = int_frame_const_col
Reported by Pylint.
Line: 1370
Column: 15
df_orig = df.copy()
def func(row):
mgr = row._mgr
row.loc["a"] += 1
assert row._mgr is not mgr
return row
expected = df.copy()
Reported by Pylint.
Line: 1372
Column: 16
def func(row):
mgr = row._mgr
row.loc["a"] += 1
assert row._mgr is not mgr
return row
expected = df.copy()
expected["a"] += 1
Reported by Pylint.
pandas/tests/libs/test_hashtable.py
196 issues
Line: 5
Column: 1
import tracemalloc
import numpy as np
import pytest
from pandas._libs import hashtable as ht
import pandas as pd
import pandas._testing as tm
Reported by Pylint.
Line: 7
Column: 1
import numpy as np
import pytest
from pandas._libs import hashtable as ht
import pandas as pd
import pandas._testing as tm
from pandas.core.algorithms import isin
Reported by Pylint.
Line: 50
Column: 53
],
)
class TestHashTable:
def test_get_set_contains_len(self, table_type, dtype):
index = 5
table = table_type(55)
assert len(table) == 0
assert index not in table
Reported by Pylint.
Line: 150
Column: 54
del table
assert get_allocated_khash_memory() == 0
def test_tracemalloc_for_empty(self, table_type, dtype):
with activated_tracemalloc():
table = table_type()
used = get_allocated_khash_memory()
my_size = table.sizeof()
assert used == my_size
Reported by Pylint.
Line: 159
Column: 42
del table
assert get_allocated_khash_memory() == 0
def test_get_state(self, table_type, dtype):
table = table_type(1000)
state = table.get_state()
assert state["size"] == 0
assert state["n_occupied"] == 0
assert "n_buckets" in state
Reported by Pylint.
Line: 309
Column: 53
],
)
class TestHashTableWithNans:
def test_get_set_contains_len(self, table_type, dtype):
index = float("nan")
table = table_type()
assert index not in table
table.set_item(index, 42)
Reported by Pylint.
Line: 372
Column: 31
assert len(unique) == 2
def get_ht_function(fun_name, type_suffix):
return getattr(ht, fun_name)
@pytest.mark.parametrize(
"dtype, type_suffix",
Reported by Pylint.
Line: 527
Column: 14
# GH-41836
values = [("a", float("nan")), ("b", 1)]
comps = [("a", float("nan"))]
result = isin(values, comps)
expected = np.array([True, False], dtype=np.bool_)
tm.assert_numpy_array_equal(result, expected)
def test_float_complex_int_are_equal_as_objects():
Reported by Pylint.
Line: 535
Column: 14
def test_float_complex_int_are_equal_as_objects():
values = ["a", 5, 5.0, 5.0 + 0j]
comps = list(range(129))
result = isin(values, comps)
expected = np.array([False, True, True, True], dtype=np.bool_)
tm.assert_numpy_array_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
from contextlib import contextmanager
import tracemalloc
import numpy as np
import pytest
from pandas._libs import hashtable as ht
import pandas as pd
Reported by Pylint.
pandas/tests/io/formats/test_to_html.py
195 issues
Line: 6
Column: 1
import re
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Index,
Reported by Pylint.
Line: 68
Column: 24
return df
@pytest.fixture(params=fmt._VALID_JUSTIFY_PARAMETERS)
def justify(request):
return request.param
@pytest.mark.parametrize("col_space", [30, 50])
Reported by Pylint.
Line: 289
Column: 5
)
# it works
df.pivot_table(index=["clé1"], columns=["clé2"])._repr_html_()
def test_to_html_truncate(datapath):
index = pd.date_range(start="20010101", freq="D", periods=20)
df = DataFrame(index=index, columns=range(20))
Reported by Pylint.
Line: 319
Column: 5
]
df = DataFrame(data)
fmt = lambda x: str(x) + "_mod"
formatters = [fmt, fmt, None, None]
result = df.to_html(formatters=formatters, max_cols=3)
expected = expected_html(datapath, "truncate_formatter")
assert result == expected
Reported by Pylint.
Line: 347
Column: 24
(None, lambda df: df.to_html(), "1"),
(None, lambda df: df.to_html(border=0), "0"),
(0, lambda df: df.to_html(), "0"),
(0, lambda df: df._repr_html_(), "0"),
],
)
def test_to_html_border(option, result, expected):
df = DataFrame({"A": [1, 2]})
if option is None:
Reported by Pylint.
Line: 362
Column: 18
@pytest.mark.parametrize("biggie_df_fixture", ["mixed"], indirect=True)
def test_to_html(biggie_df_fixture):
# TODO: split this test
df = biggie_df_fixture
s = df.to_html()
buf = StringIO()
Reported by Pylint.
Line: 363
Column: 3
@pytest.mark.parametrize("biggie_df_fixture", ["mixed"], indirect=True)
def test_to_html(biggie_df_fixture):
# TODO: split this test
df = biggie_df_fixture
s = df.to_html()
buf = StringIO()
retval = df.to_html(buf=buf)
Reported by Pylint.
Line: 382
Column: 34
@pytest.mark.parametrize("biggie_df_fixture", ["empty"], indirect=True)
def test_to_html_empty_dataframe(biggie_df_fixture):
df = biggie_df_fixture
df.to_html()
def test_to_html_filename(biggie_df_fixture, tmpdir):
Reported by Pylint.
Line: 387
Column: 27
df.to_html()
def test_to_html_filename(biggie_df_fixture, tmpdir):
df = biggie_df_fixture
expected = df.to_html()
path = tmpdir.join("test.html")
df.to_html(path)
result = path.read()
Reported by Pylint.
Line: 426
Column: 38
),
],
)
def test_to_html_multiindex(columns, justify, expected, datapath):
df = DataFrame([list("abcd"), list("efgh")], columns=columns)
result = df.to_html(justify=justify)
expected = expected_html(datapath, expected)
assert result == expected
Reported by Pylint.