The following issues were found
pandas/tests/resample/test_resampler_grouper.py
71 issues
Line: 4
Column: 1
from textwrap import dedent
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas.util._test_decorators import async_mark
import pandas as pd
Reported by Pylint.
Line: 28
Column: 5
@async_mark()
@td.check_file_leaks
async def test_tab_complete_ipython6_warning(ip):
from IPython.core.completer import provisionalcompleter
code = dedent(
"""\
import pandas._testing as tm
s = tm.makeTimeSeries()
Reported by Pylint.
Line: 81
Column: 5
}
).set_index("date")
def f(x):
return x.resample("1D").ffill()
expected = df.groupby("group").apply(f)
result = df.groupby("group").resample("1D").ffill()
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 257
Column: 5
result = r.apply(f)
tm.assert_frame_equal(result, expected)
def f(x):
return x.resample("2s").apply(lambda y: y.sum())
result = g.apply(f)
# y.sum() results in int64 instead of int32 on 32-bit architectures
expected = expected.astype("int64")
Reported by Pylint.
Line: 209
Column: 64
for f in ["first", "last", "median", "sem", "sum", "mean", "min", "max"]:
result = getattr(r, f)()
expected = g.apply(lambda x: getattr(x.resample("2s"), f)())
tm.assert_frame_equal(result, expected)
for f in ["size"]:
result = getattr(r, f)()
expected = g.apply(lambda x: getattr(x.resample("2s"), f)())
Reported by Pylint.
Line: 271
Column: 11
index = date_range("1-1-2015", "12-31-15", freq="D")
df = DataFrame(data={"col1": np.random.rand(len(index))}, index=index)
def f(x):
s = Series([1, 2], index=["a", "b"])
return s
expected = df.groupby(pd.Grouper(freq="M")).apply(f)
Reported by Pylint.
Line: 292
Column: 37
ind = date_range(start="2017-01-01", freq="15Min", periods=8)
df = DataFrame(np.array([0] * 16).reshape(8, 2), index=ind, columns=cols)
agg_dict = {col: (np.sum if col[3] == "one" else np.mean) for col in df.columns}
result = df.resample("H").apply(lambda x: agg_dict[x.name](x))
expected = DataFrame(
2 * [[0, 0.0]],
index=date_range(start="2017-01-01", freq="1H", periods=2),
columns=pd.MultiIndex.from_tuples(
[("A", "a", "", "one"), ("B", "b", "i", "two")]
Reported by Pylint.
Line: 429
Column: 14
df2 = DataFrame({"key": "B", "date": dates, "col1": range(15)})
df = pd.concat([df1, df2], ignore_index=True)
if consolidate:
df = df._consolidate()
result = df.groupby(["key"]).resample("W", on="date").min()
idx = pd.MultiIndex.from_arrays(
[
["A"] * 3 + ["B"] * 3,
Reported by Pylint.
Line: 1
Column: 1
from textwrap import dedent
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas.util._test_decorators import async_mark
import pandas as pd
Reported by Pylint.
Line: 27
Column: 1
@async_mark()
@td.check_file_leaks
async def test_tab_complete_ipython6_warning(ip):
from IPython.core.completer import provisionalcompleter
code = dedent(
"""\
import pandas._testing as tm
Reported by Pylint.
pandas/core/dtypes/dtypes.py
71 issues
Line: 15
Column: 1
)
import numpy as np
import pytz
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs import (
BaseOffset,
Reported by Pylint.
Line: 17
Column: 1
import numpy as np
import pytz
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs import (
BaseOffset,
NaT,
Period,
Reported by Pylint.
Line: 17
Column: 1
import numpy as np
import pytz
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs import (
BaseOffset,
NaT,
Period,
Reported by Pylint.
Line: 18
Column: 1
import pytz
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs import (
BaseOffset,
NaT,
Period,
Timestamp,
Reported by Pylint.
Line: 18
Column: 1
import pytz
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs import (
BaseOffset,
NaT,
Period,
Timestamp,
Reported by Pylint.
Line: 19
Column: 1
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs import (
BaseOffset,
NaT,
Period,
Timestamp,
dtypes,
Reported by Pylint.
Line: 53
Column: 5
if TYPE_CHECKING:
from datetime import tzinfo
import pyarrow
from pandas import (
Categorical,
Index,
)
Reported by Pylint.
Line: 990
Column: 9
"""
Construct PeriodArray from pyarrow Array/ChunkedArray.
"""
import pyarrow
from pandas.core.arrays import PeriodArray
from pandas.core.arrays._arrow_utils import pyarrow_array_to_numpy_and_mask
if isinstance(array, pyarrow.Array):
Reported by Pylint.
Line: 1226
Column: 9
"""
Construct IntervalArray from pyarrow Array/ChunkedArray.
"""
import pyarrow
from pandas.core.arrays import IntervalArray
if isinstance(array, pyarrow.Array):
chunks = [array]
Reported by Pylint.
Line: 116
Column: 5
the type of CategoricalDtype, this metaclass determines subclass ability
"""
pass
@register_extension_dtype
class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
"""
Reported by Pylint.
pandas/tests/strings/test_extract.py
71 issues
Line: 5
Column: 1
import re
import numpy as np
import pytest
from pandas import (
DataFrame,
Index,
MultiIndex,
Reported by Pylint.
Line: 17
Column: 3
def test_extract_expand_kwarg_wrong_type_raises(any_string_dtype):
# TODO: should this raise TypeError
values = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
with pytest.raises(ValueError, match="expand must be True or False"):
values.str.extract(".*(BAD[_]+).*(BAD)", expand=None)
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import re
import numpy as np
import pytest
from pandas import (
DataFrame,
Index,
Reported by Pylint.
Line: 16
Column: 1
)
def test_extract_expand_kwarg_wrong_type_raises(any_string_dtype):
# TODO: should this raise TypeError
values = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
with pytest.raises(ValueError, match="expand must be True or False"):
values.str.extract(".*(BAD[_]+).*(BAD)", expand=None)
Reported by Pylint.
Line: 23
Column: 1
values.str.extract(".*(BAD[_]+).*(BAD)", expand=None)
def test_extract_expand_kwarg(any_string_dtype):
s = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
expected = DataFrame(["BAD__", np.nan, np.nan], dtype=any_string_dtype)
result = s.str.extract(".*(BAD[_]+).*")
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 24
Column: 5
def test_extract_expand_kwarg(any_string_dtype):
s = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
expected = DataFrame(["BAD__", np.nan, np.nan], dtype=any_string_dtype)
result = s.str.extract(".*(BAD[_]+).*")
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 40
Column: 1
tm.assert_frame_equal(result, expected)
def test_extract_expand_False_mixed_object():
ser = Series(
["aBAD_BAD", np.nan, "BAD_b_BAD", True, datetime.today(), "foo", None, 1, 2.0]
)
# two groups
Reported by Pylint.
Line: 40
Column: 1
tm.assert_frame_equal(result, expected)
def test_extract_expand_False_mixed_object():
ser = Series(
["aBAD_BAD", np.nan, "BAD_b_BAD", True, datetime.today(), "foo", None, 1, 2.0]
)
# two groups
Reported by Pylint.
Line: 47
Column: 5
# two groups
result = ser.str.extract(".*(BAD[_]+).*(BAD)", expand=False)
er = [np.nan, np.nan] # empty row
expected = DataFrame([["BAD_", "BAD"], er, ["BAD_", "BAD"], er, er, er, er, er, er])
tm.assert_frame_equal(result, expected)
# single group
result = ser.str.extract(".*(BAD[_]+).*BAD", expand=False)
Reported by Pylint.
Line: 59
Column: 1
tm.assert_series_equal(result, expected)
def test_extract_expand_index_raises():
# GH9980
# Index only works with one regex group since
# multi-group would expand to a frame
idx = Index(["A1", "A2", "A3", "A4", "B5"])
msg = "only one regex group is supported with Index"
Reported by Pylint.
pandas/tests/extension/base/dtype.py
71 issues
Line: 4
Column: 1
import warnings
import numpy as np
import pytest
import pandas as pd
from pandas.api.types import (
infer_dtype,
is_object_dtype,
Reported by Pylint.
Line: 75
Column: 3
{"A": pd.Series(data, dtype=dtype), "B": data, "C": "foo", "D": 1}
)
# TODO(numpy-1.20): This warnings filter and if block can be removed
# once we require numpy>=1.20
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
result = df.dtypes == str(dtype)
# NumPy>=1.20.0, but not pandas.compat.numpy till there
Reported by Pylint.
Line: 129
Column: 16
# (we shortcut to just use that dtype as the common dtype), but
# still testing as good practice to have this working (and it is the
# only case we can test in general)
assert dtype._get_common_dtype([dtype]) == dtype
@pytest.mark.parametrize("skipna", [True, False])
def test_infer_dtype(self, data, data_missing, skipna):
# only testing that this works without raising an error
res = infer_dtype(data, skipna=skipna)
Reported by Pylint.
Line: 1
Column: 1
import warnings
import numpy as np
import pytest
import pandas as pd
from pandas.api.types import (
infer_dtype,
is_object_dtype,
Reported by Pylint.
Line: 15
Column: 1
from pandas.tests.extension.base.base import BaseExtensionTests
class BaseDtypeTests(BaseExtensionTests):
"""Base class for ExtensionDtype classes"""
def test_name(self, dtype):
assert isinstance(dtype.name, str)
Reported by Pylint.
Line: 18
Column: 5
class BaseDtypeTests(BaseExtensionTests):
"""Base class for ExtensionDtype classes"""
def test_name(self, dtype):
assert isinstance(dtype.name, str)
def test_kind(self, dtype):
valid = set("biufcmMOSUV")
assert dtype.kind in valid
Reported by Pylint.
Line: 18
Column: 5
class BaseDtypeTests(BaseExtensionTests):
"""Base class for ExtensionDtype classes"""
def test_name(self, dtype):
assert isinstance(dtype.name, str)
def test_kind(self, dtype):
valid = set("biufcmMOSUV")
assert dtype.kind in valid
Reported by Pylint.
Line: 19
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
"""Base class for ExtensionDtype classes"""
def test_name(self, dtype):
assert isinstance(dtype.name, str)
def test_kind(self, dtype):
valid = set("biufcmMOSUV")
assert dtype.kind in valid
Reported by Bandit.
Line: 21
Column: 5
def test_name(self, dtype):
assert isinstance(dtype.name, str)
def test_kind(self, dtype):
valid = set("biufcmMOSUV")
assert dtype.kind in valid
def test_construct_from_string_own_name(self, dtype):
result = dtype.construct_from_string(dtype.name)
Reported by Pylint.
Line: 21
Column: 5
def test_name(self, dtype):
assert isinstance(dtype.name, str)
def test_kind(self, dtype):
valid = set("biufcmMOSUV")
assert dtype.kind in valid
def test_construct_from_string_own_name(self, dtype):
result = dtype.construct_from_string(dtype.name)
Reported by Pylint.
pandas/tests/arrays/integer/test_dtypes.py
70 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas.core.dtypes.generic import ABCIndex
import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.integer import (
Int8Dtype,
Reported by Pylint.
Line: 26
Column: 3
@pytest.mark.parametrize("op", ["sum", "min", "max", "prod"])
def test_preserve_dtypes(op):
# TODO(#22346): preserve Int64 dtype
# for ops that enable (mean would actually work here
# but generally it is a float return value)
df = pd.DataFrame(
{
"A": ["a", "b", "b"],
Reported by Pylint.
Line: 91
Column: 11
other = all_data
dtype = all_data.dtype
idx = pd.Index._with_infer(np.array(other))
assert isinstance(idx, ABCIndex)
result = idx.astype(dtype)
expected = idx.astype(object).astype(dtype)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 121
Column: 26
# coerce to same numpy_dtype - ints
s = pd.Series(ints)
result = s.astype(all_data.dtype.numpy_dtype)
expected = pd.Series(ints._data.astype(all_data.dtype.numpy_dtype))
tm.assert_series_equal(result, expected)
# coerce to same type - mixed
s = pd.Series(mixed)
result = s.astype(all_data.dtype)
Reported by Pylint.
Line: 156
Column: 33
# copy=True -> ensure both data and mask are actual copies
result = arr.astype("Int64", copy=True)
assert result is not arr
assert not np.shares_memory(result._data, arr._data)
assert not np.shares_memory(result._mask, arr._mask)
result[0] = 10
tm.assert_extension_array_equal(arr, orig)
result[0] = pd.NA
tm.assert_extension_array_equal(arr, orig)
Reported by Pylint.
Line: 156
Column: 47
# copy=True -> ensure both data and mask are actual copies
result = arr.astype("Int64", copy=True)
assert result is not arr
assert not np.shares_memory(result._data, arr._data)
assert not np.shares_memory(result._mask, arr._mask)
result[0] = 10
tm.assert_extension_array_equal(arr, orig)
result[0] = pd.NA
tm.assert_extension_array_equal(arr, orig)
Reported by Pylint.
Line: 157
Column: 33
result = arr.astype("Int64", copy=True)
assert result is not arr
assert not np.shares_memory(result._data, arr._data)
assert not np.shares_memory(result._mask, arr._mask)
result[0] = 10
tm.assert_extension_array_equal(arr, orig)
result[0] = pd.NA
tm.assert_extension_array_equal(arr, orig)
Reported by Pylint.
Line: 157
Column: 47
result = arr.astype("Int64", copy=True)
assert result is not arr
assert not np.shares_memory(result._data, arr._data)
assert not np.shares_memory(result._mask, arr._mask)
result[0] = 10
tm.assert_extension_array_equal(arr, orig)
result[0] = pd.NA
tm.assert_extension_array_equal(arr, orig)
Reported by Pylint.
Line: 166
Column: 43
# copy=False
result = arr.astype("Int64", copy=False)
assert result is arr
assert np.shares_memory(result._data, arr._data)
assert np.shares_memory(result._mask, arr._mask)
result[0] = 10
assert arr[0] == 10
result[0] = pd.NA
assert arr[0] is pd.NA
Reported by Pylint.
Line: 166
Column: 29
# copy=False
result = arr.astype("Int64", copy=False)
assert result is arr
assert np.shares_memory(result._data, arr._data)
assert np.shares_memory(result._mask, arr._mask)
result[0] = 10
assert arr[0] == 10
result[0] = pd.NA
assert arr[0] is pd.NA
Reported by Pylint.
pandas/tests/tseries/offsets/test_business_day.py
70 issues
Line: 10
Column: 1
timedelta,
)
import pytest
from pandas._libs.tslibs.offsets import (
ApplyTypeError,
BDay,
BMonthEnd,
Reported by Pylint.
Line: 12
Column: 1
import pytest
from pandas._libs.tslibs.offsets import (
ApplyTypeError,
BDay,
BMonthEnd,
)
Reported by Pylint.
Line: 12
Column: 1
import pytest
from pandas._libs.tslibs.offsets import (
ApplyTypeError,
BDay,
BMonthEnd,
)
Reported by Pylint.
Line: 35
Column: 28
class TestBusinessDay(Base):
_offset = BDay
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
self.offset = BDay()
self.offset1 = self.offset
self.offset2 = BDay(2)
Reported by Pylint.
Line: 38
Column: 9
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
self.offset = BDay()
self.offset1 = self.offset
self.offset2 = BDay(2)
def test_different_normalize_equals(self):
# GH#21404 changed __eq__ to return False when `normalize` does not match
Reported by Pylint.
Line: 39
Column: 9
self.d = datetime(2008, 1, 1)
self.offset = BDay()
self.offset1 = self.offset
self.offset2 = BDay(2)
def test_different_normalize_equals(self):
# GH#21404 changed __eq__ to return False when `normalize` does not match
offset = self._offset()
Reported by Pylint.
Line: 40
Column: 9
self.offset = BDay()
self.offset1 = self.offset
self.offset2 = BDay(2)
def test_different_normalize_equals(self):
# GH#21404 changed __eq__ to return False when `normalize` does not match
offset = self._offset()
offset2 = self._offset(normalize=True)
Reported by Pylint.
Line: 29
Column: 1
)
from pandas.tests.tseries.offsets.test_offsets import _ApplyCases
from pandas.tseries import offsets as offsets
class TestBusinessDay(Base):
_offset = BDay
Reported by Pylint.
Line: 32
Column: 1
from pandas.tseries import offsets as offsets
class TestBusinessDay(Base):
_offset = BDay
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
Reported by Pylint.
Line: 35
Column: 5
class TestBusinessDay(Base):
_offset = BDay
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
self.offset = BDay()
self.offset1 = self.offset
self.offset2 = BDay(2)
Reported by Pylint.
pandas/tests/io/formats/style/test_matplotlib.py
70 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
IndexSlice,
Series,
)
Reported by Pylint.
Line: 22
Column: 12
@pytest.fixture
def styler(df):
return Styler(df, uuid_len=0)
@pytest.fixture
def df_blank():
Reported by Pylint.
Line: 32
Column: 18
@pytest.fixture
def styler_blank(df_blank):
return Styler(df_blank, uuid_len=0)
@pytest.mark.parametrize("f", ["background_gradient", "text_gradient"])
def test_function_gradient(styler, f):
Reported by Pylint.
Line: 37
Column: 28
@pytest.mark.parametrize("f", ["background_gradient", "text_gradient"])
def test_function_gradient(styler, f):
for c_map in [None, "YlOrRd"]:
result = getattr(styler, f)(cmap=c_map)._compute().ctx
assert all("#" in x[0][1] for x in result.values())
assert result[(0, 0)] == result[(0, 1)]
assert result[(1, 0)] == result[(1, 1)]
Reported by Pylint.
Line: 39
Column: 18
@pytest.mark.parametrize("f", ["background_gradient", "text_gradient"])
def test_function_gradient(styler, f):
for c_map in [None, "YlOrRd"]:
result = getattr(styler, f)(cmap=c_map)._compute().ctx
assert all("#" in x[0][1] for x in result.values())
assert result[(0, 0)] == result[(0, 1)]
assert result[(1, 0)] == result[(1, 1)]
Reported by Pylint.
Line: 46
Column: 36
@pytest.mark.parametrize("f", ["background_gradient", "text_gradient"])
def test_background_gradient_color(styler, f):
result = getattr(styler, f)(subset=IndexSlice[1, "A"])._compute().ctx
if f == "background_gradient":
assert result[(1, 0)] == [("background-color", "#fff7fb"), ("color", "#000000")]
elif f == "text_gradient":
assert result[(1, 0)] == [("color", "#fff7fb")]
Reported by Pylint.
Line: 47
Column: 14
@pytest.mark.parametrize("f", ["background_gradient", "text_gradient"])
def test_background_gradient_color(styler, f):
result = getattr(styler, f)(subset=IndexSlice[1, "A"])._compute().ctx
if f == "background_gradient":
assert result[(1, 0)] == [("background-color", "#fff7fb"), ("color", "#000000")]
elif f == "text_gradient":
assert result[(1, 0)] == [("color", "#fff7fb")]
Reported by Pylint.
Line: 63
Column: 35
],
)
@pytest.mark.parametrize("f", ["background_gradient", "text_gradient"])
def test_background_gradient_axis(styler, axis, expected, f):
if f == "background_gradient":
colors = {
"low": [("background-color", "#f7fbff"), ("color", "#000000")],
"mid": [("background-color", "#abd0e6"), ("color", "#000000")],
"high": [("background-color", "#08306b"), ("color", "#f1f1f1")],
Reported by Pylint.
Line: 76
Column: 14
"mid": [("color", "#abd0e6")],
"high": [("color", "#08306b")],
}
result = getattr(styler, f)(cmap="Blues", axis=axis)._compute().ctx
for i, cell in enumerate([(0, 0), (0, 1), (1, 0), (1, 1)]):
assert result[cell] == colors[expected[i]]
@pytest.mark.parametrize(
Reported by Pylint.
Line: 109
Column: 5
)
def test_text_color_threshold(cmap, expected):
# GH 39888
df = DataFrame(np.arange(100).reshape(10, 10))
result = df.style.background_gradient(cmap=cmap, axis=None)._compute().ctx
for k in expected.keys():
assert result[k] == expected[k]
Reported by Pylint.
pandas/core/indexes/datetimes.py
70 issues
Line: 19
Column: 1
import numpy as np
from pandas._libs import (
NaT,
Period,
Timestamp,
index as libindex,
lib,
Reported by Pylint.
Line: 19
Column: 1
import numpy as np
from pandas._libs import (
NaT,
Period,
Timestamp,
index as libindex,
lib,
Reported by Pylint.
Line: 26
Column: 1
index as libindex,
lib,
)
from pandas._libs.tslibs import (
Resolution,
timezones,
to_offset,
)
from pandas._libs.tslibs.offsets import prefix_mapping
Reported by Pylint.
Line: 31
Column: 1
timezones,
to_offset,
)
from pandas._libs.tslibs.offsets import prefix_mapping
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
Reported by Pylint.
Line: 31
Column: 1
timezones,
to_offset,
)
from pandas._libs.tslibs.offsets import prefix_mapping
from pandas._typing import (
Dtype,
DtypeObj,
npt,
)
Reported by Pylint.
Line: 595
Column: 23
def _can_partial_date_slice(self, reso: Resolution) -> bool:
# History of conversation GH#3452, GH#3931, GH#2369, GH#14826
return reso > self._resolution_obj
def _deprecate_mismatched_indexing(self, key) -> None:
# GH#36148
# we get here with isinstance(key, self._data._recognized_scalars)
try:
Reported by Pylint.
Line: 782
Column: 60
# sure we can't have ambiguous indexing
return "datetime64"
def indexer_at_time(self, time, asof: bool = False) -> npt.NDArray[np.intp]:
"""
Return index locations of values at particular time of day
(e.g. 9:30AM).
Parameters
Reported by Pylint.
Line: 823
Column: 10
def indexer_between_time(
self, start_time, end_time, include_start: bool = True, include_end: bool = True
) -> npt.NDArray[np.intp]:
"""
Return index locations of values between particular times of day
(e.g., 9:00-9:30AM).
Parameters
Reported by Pylint.
Line: 87
Column: 19
# a DatetimeArray to adapt to the newer _simple_new signature
tz = d.pop("tz")
freq = d.pop("freq")
dta = DatetimeArray._simple_new(data, dtype=tz_to_dtype(tz), freq=freq)
else:
dta = data
for key in ["tz", "freq"]:
# These are already stored in our DatetimeArray; if they are
# also in the pickle and don't match, we have a problem.
Reported by Pylint.
Line: 96
Column: 18
if key in d:
assert d[key] == getattr(dta, key)
d.pop(key)
result = cls._simple_new(dta, **d)
else:
with warnings.catch_warnings():
# TODO: If we knew what was going in to **d, we might be able to
# go through _simple_new instead
warnings.simplefilter("ignore")
Reported by Pylint.
pandas/tests/indexes/multi/test_duplicates.py
70 issues
Line: 4
Column: 1
from itertools import product
import numpy as np
import pytest
from pandas._libs import hashtable
from pandas import (
DatetimeIndex,
Reported by Pylint.
Line: 6
Column: 1
import numpy as np
import pytest
from pandas._libs import hashtable
from pandas import (
DatetimeIndex,
MultiIndex,
)
Reported by Pylint.
Line: 252
Column: 3
def test_duplicated2():
# TODO: more informative test name
# GH5873
for a in [101, 102]:
mi = MultiIndex.from_arrays([[101, a], [3.5, np.nan]])
assert not mi.has_duplicates
Reported by Pylint.
Line: 1
Column: 1
from itertools import product
import numpy as np
import pytest
from pandas._libs import hashtable
from pandas import (
DatetimeIndex,
Reported by Pylint.
Line: 16
Column: 1
@pytest.mark.parametrize("names", [None, ["first", "second"]])
def test_unique(names):
mi = MultiIndex.from_arrays([[1, 2, 1, 2], [1, 1, 1, 2]], names=names)
res = mi.unique()
exp = MultiIndex.from_arrays([[1, 2, 2], [1, 1, 2]], names=mi.names)
tm.assert_index_equal(res, exp)
Reported by Pylint.
Line: 17
Column: 5
@pytest.mark.parametrize("names", [None, ["first", "second"]])
def test_unique(names):
mi = MultiIndex.from_arrays([[1, 2, 1, 2], [1, 1, 1, 2]], names=names)
res = mi.unique()
exp = MultiIndex.from_arrays([[1, 2, 2], [1, 1, 2]], names=mi.names)
tm.assert_index_equal(res, exp)
Reported by Pylint.
Line: 23
Column: 5
exp = MultiIndex.from_arrays([[1, 2, 2], [1, 1, 2]], names=mi.names)
tm.assert_index_equal(res, exp)
mi = MultiIndex.from_arrays([list("aaaa"), list("abab")], names=names)
res = mi.unique()
exp = MultiIndex.from_arrays([list("aa"), list("ab")], names=mi.names)
tm.assert_index_equal(res, exp)
mi = MultiIndex.from_arrays([list("aaaa"), list("aaaa")], names=names)
Reported by Pylint.
Line: 28
Column: 5
exp = MultiIndex.from_arrays([list("aa"), list("ab")], names=mi.names)
tm.assert_index_equal(res, exp)
mi = MultiIndex.from_arrays([list("aaaa"), list("aaaa")], names=names)
res = mi.unique()
exp = MultiIndex.from_arrays([["a"], ["a"]], names=mi.names)
tm.assert_index_equal(res, exp)
# GH #20568 - empty MI
Reported by Pylint.
Line: 34
Column: 5
tm.assert_index_equal(res, exp)
# GH #20568 - empty MI
mi = MultiIndex.from_arrays([[], []], names=names)
res = mi.unique()
tm.assert_index_equal(mi, res)
def test_unique_datetimelike():
Reported by Pylint.
Line: 39
Column: 1
tm.assert_index_equal(mi, res)
def test_unique_datetimelike():
idx1 = DatetimeIndex(
["2015-01-01", "2015-01-01", "2015-01-01", "2015-01-01", "NaT", "NaT"]
)
idx2 = DatetimeIndex(
["2015-01-01", "2015-01-01", "2015-01-02", "2015-01-02", "NaT", "2015-01-01"],
Reported by Pylint.
pandas/tests/series/methods/test_sort_index.py
70 issues
Line: 4
Column: 1
import random
import numpy as np
import pytest
from pandas import (
DatetimeIndex,
IntervalIndex,
MultiIndex,
Reported by Pylint.
Line: 26
Column: 33
assert result.name == datetime_series.name
def test_sort_index(self, datetime_series):
datetime_series.index = datetime_series.index._with_freq(None)
rindex = list(datetime_series.index)
random.shuffle(rindex)
random_order = datetime_series.reindex(rindex)
Reported by Pylint.
Line: 60
Column: 33
random_order.sort_index(level=0, axis=1)
def test_sort_index_inplace(self, datetime_series):
datetime_series.index = datetime_series.index._with_freq(None)
# For GH#11402
rindex = list(datetime_series.index)
random.shuffle(rindex)
Reported by Pylint.
Line: 72
Column: 26
assert result is None
expected = datetime_series.reindex(datetime_series.index[::-1])
expected.index = expected.index._with_freq(None)
tm.assert_series_equal(random_order, expected)
# ascending
random_order = datetime_series.reindex(rindex)
result = random_order.sort_index(ascending=True, inplace=True)
Reported by Pylint.
Line: 81
Column: 26
assert result is None
expected = datetime_series.copy()
expected.index = expected.index._with_freq(None)
tm.assert_series_equal(random_order, expected)
def test_sort_index_level(self):
mi = MultiIndex.from_tuples([[1, 1, 3], [1, 1, 1]], names=list("ABC"))
s = Series([1, 2], mi)
Reported by Pylint.
Line: 117
Column: 36
res = s.sort_index(level=level, sort_remaining=False)
tm.assert_series_equal(s, res)
def test_sort_index_kind(self, sort_kind):
# GH#14444 & GH#13589: Add support for sort algo choosing
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
index_sorted_series = series.sort_index(kind=sort_kind)
Reported by Pylint.
Line: 272
Column: 40
result = series.sort_index(key=lambda x: 2 * x)
tm.assert_series_equal(result, series)
def test_sort_index_kind_key(self, sort_kind, sort_by_key):
# GH #14444 & #13589: Add support for sort algo choosing
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
index_sorted_series = series.sort_index(kind=sort_kind, key=sort_by_key)
Reported by Pylint.
Line: 280
Column: 44
index_sorted_series = series.sort_index(kind=sort_kind, key=sort_by_key)
tm.assert_series_equal(expected_series, index_sorted_series)
def test_sort_index_kind_neg_key(self, sort_kind):
# GH #14444 & #13589: Add support for sort algo choosing
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
expected_series = Series(index=[4, 3, 3, 2, 1], dtype=object)
index_sorted_series = series.sort_index(kind=sort_kind, key=lambda x: -x)
Reported by Pylint.
Line: 1
Column: 1
import random
import numpy as np
import pytest
from pandas import (
DatetimeIndex,
IntervalIndex,
MultiIndex,
Reported by Pylint.
Line: 16
Column: 1
@pytest.fixture(params=["quicksort", "mergesort", "heapsort", "stable"])
def sort_kind(request):
return request.param
class TestSeriesSortIndex:
def test_sort_index_name(self, datetime_series):
Reported by Pylint.