The following issues were found
pandas/tests/indexing/test_iloc.py
283 issues
Line: 11
Column: 1
)
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
NA,
Reported by Pylint.
Line: 76
Column: 20
cat = Categorical(["alpha", "beta", "gamma"])
if not using_array_manager:
assert frame._mgr.blocks[0]._can_hold_element(cat)
df = frame.copy()
orig_vals = df.values
indexer(df)[key, 0] = cat
Reported by Pylint.
Line: 76
Column: 20
cat = Categorical(["alpha", "beta", "gamma"])
if not using_array_manager:
assert frame._mgr.blocks[0]._can_hold_element(cat)
df = frame.copy()
orig_vals = df.values
indexer(df)[key, 0] = cat
Reported by Pylint.
Line: 85
Column: 3
overwrite = isinstance(key, slice) and key == slice(None)
if overwrite or using_array_manager:
# TODO(ArrayManager) we always overwrite because ArrayManager takes
# the "split" path, which still overwrites
# TODO: GH#39986 this probably shouldn't behave differently
expected = DataFrame({0: cat})
assert not np.shares_memory(df.values, orig_vals)
else:
Reported by Pylint.
Line: 87
Column: 3
if overwrite or using_array_manager:
# TODO(ArrayManager) we always overwrite because ArrayManager takes
# the "split" path, which still overwrites
# TODO: GH#39986 this probably shouldn't behave differently
expected = DataFrame({0: cat})
assert not np.shares_memory(df.values, orig_vals)
else:
expected = DataFrame({0: cat}).astype(object)
if not using_array_manager:
Reported by Pylint.
Line: 104
Column: 3
else:
assert cat[0] != "gamma"
# TODO with mixed dataframe ("split" path), we always overwrite the column
frame = DataFrame({0: np.array([0, 1, 2], dtype=object), 1: range(3)})
df = frame.copy()
orig_vals = df.values
indexer(df)[key, 0] = cat
expected = DataFrame({0: cat, 1: range(3)})
Reported by Pylint.
Line: 112
Column: 3
expected = DataFrame({0: cat, 1: range(3)})
tm.assert_frame_equal(df, expected)
# TODO(ArrayManager) does not yet update parent
@td.skip_array_manager_not_yet_implemented
@pytest.mark.parametrize("box", [array, Series])
def test_iloc_setitem_ea_inplace(self, frame_or_series, box, using_array_manager):
# GH#38952 Case with not setting a full column
# IntegerArray without NAs
Reported by Pylint.
Line: 148
Column: 16
index = Index([1, 2, 1])
ser = Series(range(3), index=index)
assert ser.iloc._is_scalar_access((1,))
df = ser.to_frame()
assert df.iloc._is_scalar_access((1, 0))
def test_iloc_exceeds_bounds(self):
Reported by Pylint.
Line: 151
Column: 16
assert ser.iloc._is_scalar_access((1,))
df = ser.to_frame()
assert df.iloc._is_scalar_access((1, 0))
def test_iloc_exceeds_bounds(self):
# GH6296
# iloc should allow indexers that exceed the bounds
Reported by Pylint.
Line: 162
Column: 13
# lists of positions should raise IndexError!
msg = "positional indexers are out-of-bounds"
with pytest.raises(IndexError, match=msg):
df.iloc[:, [0, 1, 2, 3, 4, 5]]
with pytest.raises(IndexError, match=msg):
df.iloc[[1, 30]]
with pytest.raises(IndexError, match=msg):
df.iloc[[1, -30]]
with pytest.raises(IndexError, match=msg):
Reported by Pylint.
pandas/tests/series/test_arithmetic.py
279 issues
Line: 5
Column: 1
import operator
import numpy as np
import pytest
import pytz
from pandas._libs.tslibs import IncompatibleFrequency
from pandas.core.dtypes.common import (
Reported by Pylint.
Line: 6
Column: 1
import numpy as np
import pytest
import pytz
from pandas._libs.tslibs import IncompatibleFrequency
from pandas.core.dtypes.common import (
is_datetime64_dtype,
Reported by Pylint.
Line: 288
Column: 19
def test_alignment_doesnt_change_tz(self):
# GH#33671
dti = date_range("2016-01-01", periods=10, tz="CET")
dti_utc = dti.tz_convert("UTC")
ser = Series(10, index=dti)
ser_utc = Series(10, index=dti_utc)
# we don't care about the result, just that original indexes are unchanged
ser * ser_utc
Reported by Pylint.
Line: 288
Column: 19
def test_alignment_doesnt_change_tz(self):
# GH#33671
dti = date_range("2016-01-01", periods=10, tz="CET")
dti_utc = dti.tz_convert("UTC")
ser = Series(10, index=dti)
ser_utc = Series(10, index=dti_utc)
# we don't care about the result, just that original indexes are unchanged
ser * ser_utc
Reported by Pylint.
Line: 425
Column: 15
assert result.name == names[2]
# datetime64tz dtype
dti = dti.tz_localize("US/Central")
dti = pd.DatetimeIndex(dti, freq="infer") # freq not preserved by tz_localize
ser = Series(dti).rename(names[1])
result = op(ser, dti)
assert result.name == names[2]
Reported by Pylint.
Line: 425
Column: 15
assert result.name == names[2]
# datetime64tz dtype
dti = dti.tz_localize("US/Central")
dti = pd.DatetimeIndex(dti, freq="infer") # freq not preserved by tz_localize
ser = Series(dti).rename(names[1])
result = op(ser, dti)
assert result.name == names[2]
Reported by Pylint.
Line: 38
Column: 21
autouse=True, scope="module", params=[0, 1000000], ids=["numexpr", "python"]
)
def switch_numexpr_min_elements(request):
_MIN_ELEMENTS = expr._MIN_ELEMENTS
expr._MIN_ELEMENTS = request.param
yield request.param
expr._MIN_ELEMENTS = _MIN_ELEMENTS
Reported by Pylint.
Line: 39
Column: 5
)
def switch_numexpr_min_elements(request):
_MIN_ELEMENTS = expr._MIN_ELEMENTS
expr._MIN_ELEMENTS = request.param
yield request.param
expr._MIN_ELEMENTS = _MIN_ELEMENTS
def _permute(obj):
Reported by Pylint.
Line: 41
Column: 5
_MIN_ELEMENTS = expr._MIN_ELEMENTS
expr._MIN_ELEMENTS = request.param
yield request.param
expr._MIN_ELEMENTS = _MIN_ELEMENTS
def _permute(obj):
return obj.take(np.random.permutation(len(obj)))
Reported by Pylint.
Line: 93
Column: 9
opname = all_arithmetic_operators
op = getattr(Series, opname)
m = MySeries([1, 2, 3], name="test")
m.x = 42
result = op(m, 1)
assert result.x == 42
def test_flex_add_scalar_fill_value(self):
# GH12723
Reported by Pylint.
pandas/tests/reshape/test_pivot.py
278 issues
Line: 9
Column: 1
from itertools import product
import numpy as np
import pytest
import pandas as pd
from pandas import (
Categorical,
DataFrame,
Reported by Pylint.
Line: 39
Column: 28
class TestPivotTable:
def setup_method(self, method):
self.data = DataFrame(
{
"A": [
"foo",
"foo",
Reported by Pylint.
Line: 40
Column: 9
class TestPivotTable:
def setup_method(self, method):
self.data = DataFrame(
{
"A": [
"foo",
"foo",
"foo",
Reported by Pylint.
Line: 206
Column: 52
expected = DataFrame({"values": [1, 2, 3, 4]}, index=exp_index)
tm.assert_frame_equal(result, expected)
def test_pivot_table_dropna_categoricals(self, dropna):
# GH 15193
categories = ["a", "b", "c", "d"]
df = DataFrame(
{
Reported by Pylint.
Line: 234
Column: 53
tm.assert_frame_equal(result, expected)
def test_pivot_with_non_observable_dropna(self, dropna):
# gh-21133
df = DataFrame(
{
"A": Categorical(
[np.nan, "low", "high", "low", "high"],
Reported by Pylint.
Line: 287
Column: 46
tm.assert_frame_equal(result, expected)
def test_pivot_with_interval_index(self, interval_values, dropna):
# GH 25814
df = DataFrame({"A": interval_values, "B": 1})
result = df.pivot_table(index="A", values="B", dropna=dropna)
expected = DataFrame({"B": 1}, index=Index(interval_values.unique(), name="A"))
if not dropna:
Reported by Pylint.
Line: 287
Column: 63
tm.assert_frame_equal(result, expected)
def test_pivot_with_interval_index(self, interval_values, dropna):
# GH 25814
df = DataFrame({"A": interval_values, "B": 1})
result = df.pivot_table(index="A", values="B", dropna=dropna)
expected = DataFrame({"B": 1}, index=Index(interval_values.unique(), name="A"))
if not dropna:
Reported by Pylint.
Line: 852
Column: 9
pd.pivot(df, index="zoo", columns="foo", values=("bar", "baz"))
def test_margins(self):
def _check_output(
result, values_col, index=["A", "B"], columns=["C"], margins_col="All"
):
col_margins = result.loc[result.index[:-1], margins_col]
expected_col_margins = self.data.groupby(index)[values_col].mean()
tm.assert_series_equal(col_margins, expected_col_margins, check_names=False)
Reported by Pylint.
Line: 852
Column: 9
pd.pivot(df, index="zoo", columns="foo", values=("bar", "baz"))
def test_margins(self):
def _check_output(
result, values_col, index=["A", "B"], columns=["C"], margins_col="All"
):
col_margins = result.loc[result.index[:-1], margins_col]
expected_col_margins = self.data.groupby(index)[values_col].mean()
tm.assert_series_equal(col_margins, expected_col_margins, check_names=False)
Reported by Pylint.
Line: 1577
Column: 37
"value2": [1, 2] * 3,
}
)
df["dt1"] = df["dt1"].apply(lambda d: pd.Timestamp(d))
df["dt2"] = df["dt2"].apply(lambda d: pd.Timestamp(d))
result = pivot_table(
df, index="label", columns=df["dt1"].dt.hour, values="value1"
)
Reported by Pylint.
pandas/tests/arithmetic/test_numeric.py
276 issues
Line: 13
Column: 1
from typing import Any
import numpy as np
import pytest
import pandas as pd
from pandas import (
Float64Index,
Index,
Reported by Pylint.
Line: 128
Column: 33
tm.assert_equal(result, expected)
result = obj != "a"
tm.assert_equal(result, ~expected)
msg = "Invalid comparison between dtype=float64 and str"
with pytest.raises(TypeError, match=msg):
obj < "a"
Reported by Pylint.
Line: 128
Column: 33
tm.assert_equal(result, expected)
result = obj != "a"
tm.assert_equal(result, ~expected)
msg = "Invalid comparison between dtype=float64 and str"
with pytest.raises(TypeError, match=msg):
obj < "a"
Reported by Pylint.
Line: 128
Column: 33
tm.assert_equal(result, expected)
result = obj != "a"
tm.assert_equal(result, ~expected)
msg = "Invalid comparison between dtype=float64 and str"
with pytest.raises(TypeError, match=msg):
obj < "a"
Reported by Pylint.
Line: 128
Column: 33
tm.assert_equal(result, expected)
result = obj != "a"
tm.assert_equal(result, ~expected)
msg = "Invalid comparison between dtype=float64 and str"
with pytest.raises(TypeError, match=msg):
obj < "a"
Reported by Pylint.
Line: 55
Column: 3
return expected
# TODO: remove this kludge once mypy stops giving false positives here
# List comprehension has incompatible type List[PandasObject]; expected List[RangeIndex]
# See GH#29725
ser_or_index: list[Any] = [Series, Index]
lefts: list[Any] = [RangeIndex(10, 40, 10)]
lefts.extend(
Reported by Pylint.
Line: 94
Column: 13
"'[<>]' not supported between instances of 'numpy.ndarray' and 'Timestamp'"
)
with pytest.raises(TypeError, match=msg):
df > ts
with pytest.raises(TypeError, match=msg):
df < ts
with pytest.raises(TypeError, match=msg):
ts < df
with pytest.raises(TypeError, match=msg):
Reported by Pylint.
Line: 96
Column: 13
with pytest.raises(TypeError, match=msg):
df > ts
with pytest.raises(TypeError, match=msg):
df < ts
with pytest.raises(TypeError, match=msg):
ts < df
with pytest.raises(TypeError, match=msg):
ts > df
Reported by Pylint.
Line: 98
Column: 13
with pytest.raises(TypeError, match=msg):
df < ts
with pytest.raises(TypeError, match=msg):
ts < df
with pytest.raises(TypeError, match=msg):
ts > df
assert not (df == ts).any().any()
assert (df != ts).all().all()
Reported by Pylint.
Line: 100
Column: 13
with pytest.raises(TypeError, match=msg):
ts < df
with pytest.raises(TypeError, match=msg):
ts > df
assert not (df == ts).any().any()
assert (df != ts).all().all()
def test_compare_invalid(self):
Reported by Pylint.
pandas/tests/dtypes/test_common.py
270 issues
Line: 6
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas.core.dtypes.cast import astype_nansafe
import pandas.core.dtypes.common as com
Reported by Pylint.
Line: 187
Column: 9
assert not com.is_sparse(np.array([1, 2, 3]))
if check_scipy:
import scipy.sparse
assert not com.is_sparse(scipy.sparse.bsr_matrix([1, 2, 3]))
@td.skip_if_no_scipy
Reported by Pylint.
Line: 194
Column: 5
@td.skip_if_no_scipy
def test_is_scipy_sparse():
from scipy.sparse import bsr_matrix
assert com.is_scipy_sparse(bsr_matrix([1, 2, 3]))
assert not com.is_scipy_sparse(SparseArray([1, 2, 3]))
Reported by Pylint.
Line: 578
Column: 9
assert com.is_extension_type(s)
if check_scipy:
import scipy.sparse
assert not com.is_extension_type(scipy.sparse.bsr_matrix([1, 2, 3]))
def test_is_extension_type_deprecation():
Reported by Pylint.
Line: 607
Column: 9
assert com.is_extension_array_dtype(s)
if check_scipy:
import scipy.sparse
assert not com.is_extension_array_dtype(scipy.sparse.bsr_matrix([1, 2, 3]))
def test_is_complex_dtype():
Reported by Pylint.
Line: 27
Column: 18
# EA & Actual Dtypes
def to_ea_dtypes(dtypes):
"""convert list of string dtypes to EA dtype"""
return [getattr(pd, dt + "Dtype") for dt in dtypes]
def to_numpy_dtypes(dtypes):
Reported by Pylint.
Line: 32
Column: 21
return [getattr(pd, dt + "Dtype") for dt in dtypes]
def to_numpy_dtypes(dtypes):
"""convert list of string dtypes to numpy dtype"""
return [getattr(np, dt) for dt in dtypes if isinstance(dt, str)]
class TestPandasDtype:
Reported by Pylint.
Line: 121
Column: 68
}
@pytest.mark.parametrize("name1,dtype1", list(dtypes.items()), ids=lambda x: str(x))
@pytest.mark.parametrize("name2,dtype2", list(dtypes.items()), ids=lambda x: str(x))
def test_dtype_equal(name1, dtype1, name2, dtype2):
# match equal to self, but not equal to other
assert com.is_dtype_equal(dtype1, dtype1)
Reported by Pylint.
Line: 122
Column: 68
@pytest.mark.parametrize("name1,dtype1", list(dtypes.items()), ids=lambda x: str(x))
@pytest.mark.parametrize("name2,dtype2", list(dtypes.items()), ids=lambda x: str(x))
def test_dtype_equal(name1, dtype1, name2, dtype2):
# match equal to self, but not equal to other
assert com.is_dtype_equal(dtype1, dtype1)
if name1 != name2:
Reported by Pylint.
Line: 466
Column: 3
assert not com.is_datetime_or_timedelta_dtype(pd.Series([1, 2]))
assert not com.is_datetime_or_timedelta_dtype(np.array(["a", "b"]))
# TODO(jreback), this is slightly suspect
assert not com.is_datetime_or_timedelta_dtype(DatetimeTZDtype("ns", "US/Eastern"))
assert com.is_datetime_or_timedelta_dtype(np.datetime64)
assert com.is_datetime_or_timedelta_dtype(np.timedelta64)
assert com.is_datetime_or_timedelta_dtype(np.array([], dtype=np.timedelta64))
Reported by Pylint.
pandas/tests/frame/indexing/test_setitem.py
262 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas.core.dtypes.base import _registry as ea_registry
from pandas.core.dtypes.common import (
Reported by Pylint.
Line: 315
Column: 14
# assert that A & C are not sharing the same base (e.g. they
# are copies)
v1 = df._mgr.arrays[1]
v2 = df._mgr.arrays[2]
tm.assert_extension_array_equal(v1, v2)
v1base = v1._data.base
v2base = v2._data.base
assert v1base is None or (id(v1base) != id(v2base))
Reported by Pylint.
Line: 316
Column: 14
# assert that A & C are not sharing the same base (e.g. they
# are copies)
v1 = df._mgr.arrays[1]
v2 = df._mgr.arrays[2]
tm.assert_extension_array_equal(v1, v2)
v1base = v1._data.base
v2base = v2._data.base
assert v1base is None or (id(v1base) != id(v2base))
Reported by Pylint.
Line: 318
Column: 18
v1 = df._mgr.arrays[1]
v2 = df._mgr.arrays[2]
tm.assert_extension_array_equal(v1, v2)
v1base = v1._data.base
v2base = v2._data.base
assert v1base is None or (id(v1base) != id(v2base))
# with nan
df2 = df.copy()
Reported by Pylint.
Line: 319
Column: 18
v2 = df._mgr.arrays[2]
tm.assert_extension_array_equal(v1, v2)
v1base = v1._data.base
v2base = v2._data.base
assert v1base is None or (id(v1base) != id(v2base))
# with nan
df2 = df.copy()
df2.iloc[1, 1] = NaT
Reported by Pylint.
Line: 408
Column: 3
expected.columns = cols
expected["C"] = expected["C"].astype("int64")
# TODO(ArrayManager) .loc still overwrites
expected["B"] = expected["B"].astype("int64")
else:
# set these with unique columns to be extra-unambiguous
expected[2] = expected[2].astype(np.int64)
expected[5] = expected[5].astype(np.int64)
Reported by Pylint.
Line: 679
Column: 44
assert expected.dtype == idx.dtype
return expected
def test_setitem_dt64series(self, idx, expected):
# convert to utc
df = DataFrame(np.random.randn(2, 1), columns=["A"])
df["B"] = idx
with tm.assert_produces_warning(FutureWarning) as m:
Reported by Pylint.
Line: 713
Column: 3
class TestDataFrameSetItemWithExpansion:
# TODO(ArrayManager) update parent (_maybe_update_cacher)
@td.skip_array_manager_not_yet_implemented
def test_setitem_listlike_views(self):
# GH#38148
df = DataFrame({"a": [1, 2, 3], "b": [4, 4, 6]})
Reported by Pylint.
Line: 786
Column: 37
result1 = df["D"]
result2 = df["E"]
tm.assert_categorical_equal(result1._mgr.array, cat)
# sorting
ser.name = "E"
tm.assert_series_equal(result2.sort_index(), ser.sort_index())
Reported by Pylint.
Line: 889
Column: 3
class TestDataFrameSetItemBooleanMask:
@td.skip_array_manager_invalid_test # TODO(ArrayManager) rewrite not using .values
@pytest.mark.parametrize(
"mask_type",
[lambda df: df > np.abs(df) / 2, lambda df: (df > np.abs(df) / 2).values],
ids=["dataframe", "array"],
)
Reported by Pylint.
pandas/tests/test_nanops.py
260 issues
Line: 6
Column: 1
import warnings
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas.core.dtypes.common import is_integer_dtype
Reported by Pylint.
Line: 373
Column: 9
@td.skip_if_no_scipy
@pytest.mark.parametrize("ddof", range(3))
def test_nansem(self, ddof, skipna):
from scipy.stats import sem
with np.errstate(invalid="ignore"):
self.check_funs(
nanops.nansem,
sem,
Reported by Pylint.
Line: 436
Column: 9
@td.skip_if_no_scipy
def test_nanskew(self, skipna):
from scipy.stats import skew
func = partial(self._skew_kurt_wrap, func=skew)
with np.errstate(invalid="ignore"):
self.check_funs(
nanops.nanskew,
Reported by Pylint.
Line: 451
Column: 9
@td.skip_if_no_scipy
def test_nankurt(self, skipna):
from scipy.stats import kurtosis
func1 = partial(kurtosis, fisher=True)
func = partial(self._skew_kurt_wrap, func=func1)
with np.errstate(invalid="ignore"):
self.check_funs(
Reported by Pylint.
Line: 583
Column: 9
@td.skip_if_no_scipy
def test_nancorr_kendall(self):
from scipy.stats import kendalltau
targ0 = kendalltau(self.arr_float_2d, self.arr_float1_2d)[0]
targ1 = kendalltau(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0]
self.check_nancorr_nancov_2d(nanops.nancorr, targ0, targ1, method="kendall")
targ0 = kendalltau(self.arr_float_1d, self.arr_float1_1d)[0]
Reported by Pylint.
Line: 594
Column: 9
@td.skip_if_no_scipy
def test_nancorr_spearman(self):
from scipy.stats import spearmanr
targ0 = spearmanr(self.arr_float_2d, self.arr_float1_2d)[0]
targ1 = spearmanr(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0]
self.check_nancorr_nancov_2d(nanops.nancorr, targ0, targ1, method="spearman")
targ0 = spearmanr(self.arr_float_1d, self.arr_float1_1d)[0]
Reported by Pylint.
Line: 893
Column: 16
@property
def prng(self):
return np.random.RandomState(1234)
class TestNanskewFixedValues:
# xref GH 11974
Reported by Pylint.
Line: 942
Column: 16
@property
def prng(self):
return np.random.RandomState(1234)
class TestNankurtFixedValues:
# xref GH 11974
Reported by Pylint.
Line: 991
Column: 16
@property
def prng(self):
return np.random.RandomState(1234)
class TestDatetime64NaNOps:
# Enabling mean changes the behavior of DataFrame.mean
# See https://github.com/pandas-dev/pandas/issues/24752
Reported by Pylint.
Line: 21
Column: 10
from pandas.core.arrays import DatetimeArray
import pandas.core.nanops as nanops
use_bn = nanops._USE_BOTTLENECK
has_c16 = hasattr(np, "complex128")
@pytest.fixture(params=[True, False])
def skipna(request):
Reported by Pylint.
pandas/tests/series/indexing/test_setitem.py
257 issues
Line: 7
Column: 1
)
import numpy as np
import pytest
from pandas import (
Categorical,
DataFrame,
DatetimeIndex,
Reported by Pylint.
Line: 309
Column: 16
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
# check that the DatetimeIndex was not altered in place
assert ser._values is not dti
Reported by Pylint.
Line: 309
Column: 16
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
# check that the DatetimeIndex was not altered in place
assert ser._values is not dti
Reported by Pylint.
Line: 317
Column: 16
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti[1] == ts
assert dti.freq == "D"
def test_dt64tz_setitem_does_not_mutate_dti(self):
# GH#21907, GH#24096
dti = date_range("2016-01-01", periods=10, tz="US/Pacific")
ts = dti[0]
Reported by Pylint.
Line: 317
Column: 16
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti[1] == ts
assert dti.freq == "D"
def test_dt64tz_setitem_does_not_mutate_dti(self):
# GH#21907, GH#24096
dti = date_range("2016-01-01", periods=10, tz="US/Pacific")
ts = dti[0]
Reported by Pylint.
Line: 307
Column: 16
dti = date_range("20130101", periods=3, tz="US/Eastern")
ts = dti[1]
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
Reported by Pylint.
Line: 308
Column: 16
ts = dti[1]
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
# check that the DatetimeIndex was not altered in place
Reported by Pylint.
Line: 308
Column: 46
ts = dti[1]
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
# check that the DatetimeIndex was not altered in place
Reported by Pylint.
Line: 308
Column: 46
ts = dti[1]
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
# check that the DatetimeIndex was not altered in place
Reported by Pylint.
Line: 308
Column: 16
ts = dti[1]
ser = Series(dti)
assert ser._values is not dti
assert ser._values._data.base is not dti._data._data.base
assert dti.freq == "D"
ser.iloc[1] = NaT
assert ser._values.freq is None
# check that the DatetimeIndex was not altered in place
Reported by Pylint.
pandas/tests/frame/methods/test_replace.py
256 issues
Line: 8
Column: 1
import re
import numpy as np
import pytest
from pandas.compat import np_version_under1p20
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 113
Column: 45
expected = DataFrame(expected)
tm.assert_frame_equal(result, expected)
def test_regex_replace_list_mixed(self, mix_ab):
# mixed frame to make sure this doesn't break things
dfmix = DataFrame(mix_ab)
# lists of regexes and values
# list of [re1, re2, ..., reN] -> [v1, v2, ..., vN]
Reported by Pylint.
Line: 154
Column: 53
expec = DataFrame({"a": mix_ab["a"], "b": ["crap", "b_crap", "..", ".."]})
tm.assert_frame_equal(res, expec)
def test_regex_replace_list_mixed_inplace(self, mix_ab):
dfmix = DataFrame(mix_ab)
# the same inplace
# lists of regexes and values
# list of [re1, re2, ..., reN] -> [v1, v2, ..., vN]
to_replace_res = [r"\s*\.\s*", r"a"]
Reported by Pylint.
Line: 194
Column: 45
expec = DataFrame({"a": mix_ab["a"], "b": ["crap", "b_crap", "..", ".."]})
tm.assert_frame_equal(res, expec)
def test_regex_replace_dict_mixed(self, mix_abc):
dfmix = DataFrame(mix_abc)
# dicts
# single dict {re1: v1}, search the whole frame
# need test for this...
Reported by Pylint.
Line: 263
Column: 46
tm.assert_frame_equal(res, expec)
tm.assert_frame_equal(res2, expec)
def test_regex_replace_dict_nested(self, mix_abc):
# nested dicts will not work until this is implemented for Series
dfmix = DataFrame(mix_abc)
res = dfmix.replace({"b": {r"\s*\.\s*": np.nan}}, regex=True)
res2 = dfmix.copy()
res4 = dfmix.copy()
Reported by Pylint.
Line: 298
Column: 49
result = df.replace({"Type": {"Q": 0, "T": 1}})
tm.assert_frame_equal(result, expected)
def test_regex_replace_list_to_scalar(self, mix_abc):
df = DataFrame(mix_abc)
expec = DataFrame(
{
"a": mix_abc["a"],
"b": np.array([np.nan] * 4),
Reported by Pylint.
Line: 322
Column: 49
tm.assert_frame_equal(res2, expec)
tm.assert_frame_equal(res3, expec)
def test_regex_replace_str_to_numeric(self, mix_abc):
# what happens when you try to replace a numeric value with a regex?
df = DataFrame(mix_abc)
res = df.replace(r"\s*\.\s*", 0, regex=True)
res2 = df.copy()
return_value = res2.replace(r"\s*\.\s*", 0, inplace=True, regex=True)
Reported by Pylint.
Line: 337
Column: 56
tm.assert_frame_equal(res2, expec)
tm.assert_frame_equal(res3, expec)
def test_regex_replace_regex_list_to_numeric(self, mix_abc):
df = DataFrame(mix_abc)
res = df.replace([r"\s*\.\s*", "b"], 0, regex=True)
res2 = df.copy()
return_value = res2.replace([r"\s*\.\s*", "b"], 0, regex=True, inplace=True)
assert return_value is None
Reported by Pylint.
Line: 353
Column: 52
tm.assert_frame_equal(res2, expec)
tm.assert_frame_equal(res3, expec)
def test_regex_replace_series_of_regexes(self, mix_abc):
df = DataFrame(mix_abc)
s1 = Series({"b": r"\s*\.\s*"})
s2 = Series({"b": np.nan})
res = df.replace(s1, s2, regex=True)
res2 = df.copy()
Reported by Pylint.
Line: 371
Column: 63
tm.assert_frame_equal(res2, expec)
tm.assert_frame_equal(res3, expec)
def test_regex_replace_numeric_to_object_conversion(self, mix_abc):
df = DataFrame(mix_abc)
expec = DataFrame({"a": ["a", 1, 2, 3], "b": mix_abc["b"], "c": mix_abc["c"]})
res = df.replace(0, "a")
tm.assert_frame_equal(res, expec)
assert res.a.dtype == np.object_
Reported by Pylint.
pandas/tests/groupby/test_grouping.py
254 issues
Line: 4
Column: 1
""" test where we are determining what we are grouping, or getting groups """
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalIndex,
DataFrame,
Reported by Pylint.
Line: 28
Column: 13
df = DataFrame([[1, 2]], columns=["A", "B"])
g = df.groupby("A")
with pytest.raises(KeyError, match="\"Columns not found: 'C'\""):
g[["C"]]
with pytest.raises(KeyError, match="^[^A]+$"):
# A should not be referenced as a bad column...
# will have to rethink regex if you change message!
g[["A", "C"]]
Reported by Pylint.
Line: 33
Column: 13
with pytest.raises(KeyError, match="^[^A]+$"):
# A should not be referenced as a bad column...
# will have to rethink regex if you change message!
g[["A", "C"]]
def test_groupby_duplicated_column_errormsg(self):
# GH7511
df = DataFrame(
columns=["A", "B", "A", "C"], data=[range(4), range(2, 6), range(0, 8, 2)]
Reported by Pylint.
Line: 381
Column: 9
def test_groupby_dict_mapping(self):
# GH #679
from pandas import Series
s = Series({"T1": 5})
result = s.groupby({"T1": "T2"}).agg(sum)
expected = s.groupby(["T2"]).agg(sum)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 381
Column: 9
def test_groupby_dict_mapping(self):
# GH #679
from pandas import Series
s = Series({"T1": 5})
result = s.groupby({"T1": "T2"}).agg(sum)
expected = s.groupby(["T2"]).agg(sum)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 553
Column: 56
if axis in (1, "columns"):
df = df.T
df.groupby(level="exp", axis=axis)
msg = f"level name foo is not the name of the {df._get_axis_name(axis)}"
with pytest.raises(ValueError, match=msg):
df.groupby(level="foo", axis=axis)
@pytest.mark.parametrize("sort", [True, False])
def test_groupby_level_with_nas(self, sort):
Reported by Pylint.
Line: 768
Column: 3
bins = [0, 5, 10, 15]
g = d.groupby(pd.cut(d[0], bins), observed=observed)
# TODO: should prob allow a str of Interval work as well
# IOW '(0, 5]'
result = g.get_group(pd.Interval(0, 5))
expected = DataFrame([3, 1], index=[0, 1])
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 865
Column: 13
grouped = tsframe.groupby([lambda x: x.weekday(), lambda x: x.year])
# test it works
for g in grouped.grouper.groupings[0]:
pass
def test_multi_iter(self):
s = Series(np.arange(6))
k1 = np.array(["a", "a", "a", "b", "b", "b"])
Reported by Pylint.
Line: 923
Column: 13
# axis = 1
three_levels = three_group.groupby(["A", "B", "C"]).mean()
grouped = three_levels.T.groupby(axis=1, level=(1, 2))
for key, group in grouped:
pass
def test_dictify(self, df):
dict(iter(df.groupby("A")))
dict(iter(df.groupby(["A", "B"])))
Reported by Pylint.
Line: 923
Column: 18
# axis = 1
three_levels = three_group.groupby(["A", "B", "C"]).mean()
grouped = three_levels.T.groupby(axis=1, level=(1, 2))
for key, group in grouped:
pass
def test_dictify(self, df):
dict(iter(df.groupby("A")))
dict(iter(df.groupby(["A", "B"])))
Reported by Pylint.