The following issues were found
pandas/tests/scalar/timedelta/test_arithmetic.py
434 issues
Line: 11
Column: 1
import operator
import numpy as np
import pytest
from pandas.errors import OutOfBoundsTimedelta
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 541
Column: 19
]
)
with pytest.raises(TypeError, match=msg):
td // np.datetime64("2016-01-01", dtype="datetime64[us]")
def test_td_floordiv_numeric_scalar(self):
# GH#18846
td = Timedelta(hours=3, minutes=4)
Reported by Pylint.
Line: 104
Column: 13
def test_td_add_timestamp_overflow(self):
msg = "int too (large|big) to convert"
with pytest.raises(OverflowError, match=msg):
Timestamp("1700-01-01") + Timedelta(13 * 19999, unit="D")
with pytest.raises(OutOfBoundsTimedelta, match=msg):
Timestamp("1700-01-01") + timedelta(days=13 * 19999)
@pytest.mark.parametrize("op", [operator.add, ops.radd])
Reported by Pylint.
Line: 107
Column: 13
Timestamp("1700-01-01") + Timedelta(13 * 19999, unit="D")
with pytest.raises(OutOfBoundsTimedelta, match=msg):
Timestamp("1700-01-01") + timedelta(days=13 * 19999)
@pytest.mark.parametrize("op", [operator.add, ops.radd])
def test_td_add_td(self, op):
td = Timedelta(10, unit="d")
Reported by Pylint.
Line: 197
Column: 17
msg = "unsupported operand type"
for other in [2, 2.0, np.int64(2), np.float64(2)]:
with pytest.raises(TypeError, match=msg):
td + other
with pytest.raises(TypeError, match=msg):
other + td
with pytest.raises(TypeError, match=msg):
td - other
with pytest.raises(TypeError, match=msg):
Reported by Pylint.
Line: 199
Column: 17
with pytest.raises(TypeError, match=msg):
td + other
with pytest.raises(TypeError, match=msg):
other + td
with pytest.raises(TypeError, match=msg):
td - other
with pytest.raises(TypeError, match=msg):
other - td
Reported by Pylint.
Line: 201
Column: 17
with pytest.raises(TypeError, match=msg):
other + td
with pytest.raises(TypeError, match=msg):
td - other
with pytest.raises(TypeError, match=msg):
other - td
def test_td_rsub_nat(self):
td = Timedelta(10, unit="d")
Reported by Pylint.
Line: 203
Column: 17
with pytest.raises(TypeError, match=msg):
td - other
with pytest.raises(TypeError, match=msg):
other - td
def test_td_rsub_nat(self):
td = Timedelta(10, unit="d")
result = NaT - td
assert result is NaT
Reported by Pylint.
Line: 245
Column: 13
arr = np.array([now, Timedelta("1D"), np.timedelta64(2, "h")])
msg = r"unsupported operand type\(s\) for \-: 'Timedelta' and 'Timestamp'"
with pytest.raises(TypeError, match=msg):
Timedelta("1D") - arr
@pytest.mark.parametrize("op", [operator.add, ops.radd])
def test_td_add_timedeltalike_object_dtype_array(self, op):
# GH#21980
arr = np.array([Timestamp("20130101 9:01"), Timestamp("20121230 9:02")])
Reported by Pylint.
Line: 264
Column: 3
res = op(arr, Timedelta("1D"))
tm.assert_numpy_array_equal(res, exp)
# TODO: moved from index tests following #24365, may need de-duplication
def test_ops_ndarray(self):
td = Timedelta("1 day")
# timedelta, timedelta
other = pd.to_timedelta(["1 day"]).values
Reported by Pylint.
pandas/tests/frame/test_query_eval.py
422 issues
Line: 5
Column: 1
import operator
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 34
Column: 30
return request.param
def skip_if_no_pandas_parser(parser):
if parser != "pandas":
pytest.skip(f"cannot evaluate with parser {repr(parser)}")
class TestCompat:
Reported by Pylint.
Line: 40
Column: 28
class TestCompat:
def setup_method(self, method):
self.df = DataFrame({"A": [1, 2, 3]})
self.expected1 = self.df[self.df.A > 0]
self.expected2 = self.df.A + 1
def test_query_default(self):
Reported by Pylint.
Line: 41
Column: 9
class TestCompat:
def setup_method(self, method):
self.df = DataFrame({"A": [1, 2, 3]})
self.expected1 = self.df[self.df.A > 0]
self.expected2 = self.df.A + 1
def test_query_default(self):
Reported by Pylint.
Line: 42
Column: 9
class TestCompat:
def setup_method(self, method):
self.df = DataFrame({"A": [1, 2, 3]})
self.expected1 = self.df[self.df.A > 0]
self.expected2 = self.df.A + 1
def test_query_default(self):
# GH 12749
Reported by Pylint.
Line: 43
Column: 9
def setup_method(self, method):
self.df = DataFrame({"A": [1, 2, 3]})
self.expected1 = self.df[self.df.A > 0]
self.expected2 = self.df.A + 1
def test_query_default(self):
# GH 12749
# this should always work, whether NUMEXPR_INSTALLED or not
Reported by Pylint.
Line: 113
Column: 9
df.iloc[0] = 2
m = df.mean()
base = DataFrame( # noqa
np.tile(m.values, n).reshape(n, -1), columns=list("abcd")
)
expected = eval(f"base {op_str} df")
Reported by Pylint.
Line: 117
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
np.tile(m.values, n).reshape(n, -1), columns=list("abcd")
)
expected = eval(f"base {op_str} df")
# ops as strings
result = eval(f"m {op_str} df")
tm.assert_frame_equal(result, expected)
Reported by Bandit.
Line: 117
Column: 20
np.tile(m.values, n).reshape(n, -1), columns=list("abcd")
)
expected = eval(f"base {op_str} df")
# ops as strings
result = eval(f"m {op_str} df")
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 120
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
expected = eval(f"base {op_str} df")
# ops as strings
result = eval(f"m {op_str} df")
tm.assert_frame_equal(result, expected)
# these are commutative
if op in ["+", "*"]:
result = getattr(df, op)(m)
Reported by Bandit.
pandas/tests/groupby/test_groupby.py
417 issues
Line: 6
Column: 1
from io import StringIO
import numpy as np
import pytest
from pandas.compat import IS64
from pandas.errors import PerformanceWarning
import pandas as pd
Reported by Pylint.
Line: 135
Column: 5
]
)
def func(dataf):
return dataf["val2"] - dataf["val2"].mean()
with tm.assert_produces_warning(FutureWarning):
result = df2.groupby("val1", squeeze=True).apply(func)
assert isinstance(result, Series)
Reported by Pylint.
Line: 167
Column: 5
result = df.groupby("A").apply(f)[["B"]]
tm.assert_frame_equal(result, expected)
def f(grp):
if grp.name == "Tiger":
return None
return grp.iloc[0]
result = df.groupby("A").apply(f)[["B"]]
Reported by Pylint.
Line: 177
Column: 5
e.loc["Tiger"] = np.nan
tm.assert_frame_equal(result, e)
def f(grp):
if grp.name == "Pony":
return None
return grp.iloc[0]
result = df.groupby("A").apply(f)[["B"]]
Reported by Pylint.
Line: 188
Column: 5
tm.assert_frame_equal(result, e)
# 5592 revisited, with datetimes
def f(grp):
if grp.name == "Pony":
return None
return grp.iloc[0]
result = df.groupby("A").apply(f)[["C"]]
Reported by Pylint.
Line: 199
Column: 5
tm.assert_frame_equal(result, e)
# scalar outputs
def f(grp):
if grp.name == "Pony":
return None
return grp.iloc[0].loc["C"]
result = df.groupby("A").apply(f)
Reported by Pylint.
Line: 48
Column: 9
grouped = data.groupby(lambda x: x // 3)
for k, v in grouped:
assert len(v) == 3
agged = grouped.aggregate(np.mean)
assert agged[1] == 1
Reported by Pylint.
Line: 266
Column: 3
}
expected = DataFrame(ex_data).T
if not as_index:
# TODO: try to get this more consistent?
expected.index = Index(range(2))
tm.assert_frame_equal(res, expected)
Reported by Pylint.
Line: 431
Column: 9
# transform propagate
transformed = grouped.transform(lambda x: x.mean())
for name, group in grouped:
mean = group.mean()
for idx in group.index:
tm.assert_series_equal(transformed.xs(idx), mean, check_names=False)
# iterate
Reported by Pylint.
Line: 464
Column: 9
tm.assert_frame_equal(groupedT.transform(tf).T, grouped.transform(tf))
# iterate
for k, v in grouped:
assert len(v.columns) == 2
def test_frame_set_name_single(df):
grouped = df.groupby("A")
Reported by Pylint.
pandas/tests/io/test_parquet.py
411 issues
Line: 12
Column: 1
)
import numpy as np
import pytest
from pandas._config import get_option
from pandas.compat import is_platform_windows
from pandas.compat.pyarrow import (
Reported by Pylint.
Line: 237
Column: 9
Expected partition names.
"""
if pa_version_under5p0:
import pyarrow.parquet as pq
dataset = pq.ParquetDataset(path, validate_schema=False)
assert len(dataset.partitions.partition_names) == len(expected)
assert dataset.partitions.partition_names == set(expected)
else:
Reported by Pylint.
Line: 243
Column: 9
assert len(dataset.partitions.partition_names) == len(expected)
assert dataset.partitions.partition_names == set(expected)
else:
import pyarrow.dataset as ds
dataset = ds.dataset(path, partitioning="hive")
assert dataset.partitioning.schema.names == expected
Reported by Pylint.
Line: 600
Column: 9
self.check_error_on_write(df, engine, ValueError, msg)
def test_use_nullable_dtypes(self, engine):
import pyarrow.parquet as pq
if engine == "fastparquet":
# We are manually disabling fastparquet's
# nullable dtype support pending discussion
pytest.skip("Fastparquet nullable dtype support is disabled")
Reported by Pylint.
Line: 649
Column: 15
# additional supported types for pyarrow
dti = pd.date_range("20130101", periods=3, tz="Europe/Brussels")
dti = dti._with_freq(None) # freq doesn't round-trip
df["datetime_tz"] = dti
df["bool_with_none"] = [True, None, True]
check_round_trip(df, pa)
Reported by Pylint.
Line: 649
Column: 15
# additional supported types for pyarrow
dti = pd.date_range("20130101", periods=3, tz="Europe/Brussels")
dti = dti._with_freq(None) # freq doesn't round-trip
df["datetime_tz"] = dti
df["bool_with_none"] = [True, None, True]
check_round_trip(df, pa)
Reported by Pylint.
Line: 843
Column: 9
check_round_trip(df, pa)
def test_write_with_schema(self, pa):
import pyarrow
df = pd.DataFrame({"x": [0, 1]})
schema = pyarrow.schema([pyarrow.field("x", type=pyarrow.bool_())])
out_df = df.astype(bool)
check_round_trip(df, pa, write_kwargs={"schema": schema}, expected=out_df)
Reported by Pylint.
Line: 940
Column: 15
df = df_full
dti = pd.date_range("20130101", periods=3, tz="US/Eastern")
dti = dti._with_freq(None) # freq doesn't round-trip
df["datetime_tz"] = dti
df["timedelta"] = pd.timedelta_range("1 day", periods=3)
check_round_trip(df, fp)
@pytest.mark.skip(reason="not supported")
Reported by Pylint.
Line: 940
Column: 15
df = df_full
dti = pd.date_range("20130101", periods=3, tz="US/Eastern")
dti = dti._with_freq(None) # freq doesn't round-trip
df["datetime_tz"] = dti
df["timedelta"] = pd.timedelta_range("1 day", periods=3)
check_round_trip(df, fp)
@pytest.mark.skip(reason="not supported")
Reported by Pylint.
Line: 1006
Column: 13
compression=None,
)
assert os.path.exists(path)
import fastparquet
actual_partition_cols = fastparquet.ParquetFile(path, False).cats
assert len(actual_partition_cols) == 2
def test_partition_cols_string(self, fp, df_full):
Reported by Pylint.
pandas/tests/internals/test_internals.py
397 issues
Line: 9
Column: 1
import re
import numpy as np
import pytest
from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td
from pandas.core.dtypes.common import is_scalar
Reported by Pylint.
Line: 11
Column: 1
import numpy as np
import pytest
from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td
from pandas.core.dtypes.common import is_scalar
import pandas as pd
Reported by Pylint.
Line: 11
Column: 1
import numpy as np
import pytest
from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td
from pandas.core.dtypes.common import is_scalar
import pandas as pd
Reported by Pylint.
Line: 46
Column: 3
)
# this file contains BlockManager specific tests
# TODO(ArrayManager) factor out interleave_dtype tests
pytestmark = td.skip_array_manager_invalid_test
@pytest.fixture(params=[new_block, make_block])
def block_maker(request):
Reported by Pylint.
Line: 143
Column: 18
assert m is not None, f"incompatible typestr -> {typestr}"
tz = m.groups()[0]
assert num_items == 1, "must have only 1 num items for a tz-aware"
values = DatetimeIndex(np.arange(N) * 1e9, tz=tz)._data
values = ensure_block_shape(values, ndim=len(shape))
elif typestr in ("timedelta", "td", "m8[ns]"):
values = (mat * 1).astype("m8[ns]")
elif typestr in ("category",):
values = Categorical([1, 1, 2, 2, 3, 3, 3, 3, 4, 4])
Reported by Pylint.
Line: 152
Column: 3
elif typestr in ("category2",):
values = Categorical(["a", "a", "a", "a", "b", "b", "c", "c", "c", "d"])
elif typestr in ("sparse", "sparse_na"):
# FIXME: doesn't support num_rows != 10
assert shape[-1] == 10
assert all(s == 1 for s in shape[:-1])
if typestr.endswith("_na"):
fill_value = np.nan
else:
Reported by Pylint.
Line: 245
Column: 28
class TestBlock:
def setup_method(self, method):
self.fblock = create_block("float", [0, 2, 4])
self.cblock = create_block("complex", [7])
self.oblock = create_block("object", [1, 3])
self.bool_block = create_block("bool", [5])
Reported by Pylint.
Line: 246
Column: 9
class TestBlock:
def setup_method(self, method):
self.fblock = create_block("float", [0, 2, 4])
self.cblock = create_block("complex", [7])
self.oblock = create_block("object", [1, 3])
self.bool_block = create_block("bool", [5])
def test_constructor(self):
Reported by Pylint.
Line: 247
Column: 9
class TestBlock:
def setup_method(self, method):
self.fblock = create_block("float", [0, 2, 4])
self.cblock = create_block("complex", [7])
self.oblock = create_block("object", [1, 3])
self.bool_block = create_block("bool", [5])
def test_constructor(self):
int32block = create_block("i4", [0])
Reported by Pylint.
Line: 248
Column: 9
def setup_method(self, method):
self.fblock = create_block("float", [0, 2, 4])
self.cblock = create_block("complex", [7])
self.oblock = create_block("object", [1, 3])
self.bool_block = create_block("bool", [5])
def test_constructor(self):
int32block = create_block("i4", [0])
assert int32block.dtype == np.int32
Reported by Pylint.
pandas/tests/reshape/merge/test_merge.py
390 issues
Line: 10
Column: 1
import re
import numpy as np
import pytest
from pandas.core.dtypes.common import (
is_categorical_dtype,
is_object_dtype,
)
Reported by Pylint.
Line: 119
Column: 28
class TestMerge:
def setup_method(self, method):
# aggregate multiple columns
self.df = DataFrame(
{
"key1": get_test_data(),
"key2": get_test_data(),
Reported by Pylint.
Line: 121
Column: 9
class TestMerge:
def setup_method(self, method):
# aggregate multiple columns
self.df = DataFrame(
{
"key1": get_test_data(),
"key2": get_test_data(),
"data1": np.random.randn(N),
"data2": np.random.randn(N),
Reported by Pylint.
Line: 131
Column: 9
)
# exclude a couple keys for fun
self.df = self.df[self.df["key2"] > 1]
self.df2 = DataFrame(
{
"key1": get_test_data(n=N // 5),
"key2": get_test_data(ngroups=NGROUPS // 2, n=N // 5),
Reported by Pylint.
Line: 133
Column: 9
# exclude a couple keys for fun
self.df = self.df[self.df["key2"] > 1]
self.df2 = DataFrame(
{
"key1": get_test_data(n=N // 5),
"key2": get_test_data(ngroups=NGROUPS // 2, n=N // 5),
"value": np.random.randn(N // 5),
}
Reported by Pylint.
Line: 141
Column: 9
}
)
self.left = DataFrame(
{"key": ["a", "b", "c", "d", "e", "e", "a"], "v1": np.random.randn(7)}
)
self.right = DataFrame({"v2": np.random.randn(4)}, index=["d", "b", "c", "a"])
def test_merge_inner_join_empty(self):
Reported by Pylint.
Line: 144
Column: 9
self.left = DataFrame(
{"key": ["a", "b", "c", "d", "e", "e", "a"], "v1": np.random.randn(7)}
)
self.right = DataFrame({"v2": np.random.randn(4)}, index=["d", "b", "c", "a"])
def test_merge_inner_join_empty(self):
# GH 15328
df_empty = DataFrame()
df_a = DataFrame({"a": [1, 2]}, index=[0, 1], dtype="int64")
Reported by Pylint.
Line: 162
Column: 9
def test_merge_non_string_columns(self):
# https://github.com/pandas-dev/pandas/issues/17962
# Checks that method runs for non string column names
left = DataFrame(
{0: [1, 0, 1, 0], 1: [0, 1, 0, 0], 2: [0, 0, 2, 0], 3: [1, 0, 0, 3]}
)
right = left.astype(float)
expected = left
Reported by Pylint.
Line: 166
Column: 9
{0: [1, 0, 1, 0], 1: [0, 1, 0, 0], 2: [0, 0, 2, 0], 3: [1, 0, 0, 3]}
)
right = left.astype(float)
expected = left
result = merge(left, right)
tm.assert_frame_equal(expected, result)
def test_merge_index_as_on_arg(self):
Reported by Pylint.
Line: 174
Column: 9
def test_merge_index_as_on_arg(self):
# GH14355
left = self.df.set_index("key1")
right = self.df2.set_index("key1")
result = merge(left, right, on="key1")
expected = merge(self.df, self.df2, on="key1").set_index("key1")
tm.assert_frame_equal(result, expected)
Reported by Pylint.
pandas/core/indexes/base.py
382 issues
Line: 25
Column: 1
from pandas._config import get_option
from pandas._libs import (
algos as libalgos,
index as libindex,
lib,
)
import pandas._libs.join as libjoin
Reported by Pylint.
Line: 25
Column: 1
from pandas._config import get_option
from pandas._libs import (
algos as libalgos,
index as libindex,
lib,
)
import pandas._libs.join as libjoin
Reported by Pylint.
Line: 25
Column: 1
from pandas._config import get_option
from pandas._libs import (
algos as libalgos,
index as libindex,
lib,
)
import pandas._libs.join as libjoin
Reported by Pylint.
Line: 30
Column: 1
index as libindex,
lib,
)
import pandas._libs.join as libjoin
from pandas._libs.lib import (
is_datetime_array,
no_default,
)
from pandas._libs.tslibs import (
Reported by Pylint.
Line: 30
Column: 1
index as libindex,
lib,
)
import pandas._libs.join as libjoin
from pandas._libs.lib import (
is_datetime_array,
no_default,
)
from pandas._libs.tslibs import (
Reported by Pylint.
Line: 31
Column: 1
lib,
)
import pandas._libs.join as libjoin
from pandas._libs.lib import (
is_datetime_array,
no_default,
)
from pandas._libs.tslibs import (
IncompatibleFrequency,
Reported by Pylint.
Line: 31
Column: 1
lib,
)
import pandas._libs.join as libjoin
from pandas._libs.lib import (
is_datetime_array,
no_default,
)
from pandas._libs.tslibs import (
IncompatibleFrequency,
Reported by Pylint.
Line: 312
Column: 64
# given the dtypes of the passed arguments
@final
def _left_indexer_unique(self: _IndexT, other: _IndexT) -> npt.NDArray[np.intp]:
# Caller is responsible for ensuring other.dtype == self.dtype
sv = self._get_join_target()
ov = other._get_join_target()
return libjoin.left_join_indexer_unique(sv, ov)
Reported by Pylint.
Line: 321
Column: 27
@final
def _left_indexer(
self: _IndexT, other: _IndexT
) -> tuple[ArrayLike, npt.NDArray[np.intp], npt.NDArray[np.intp]]:
# Caller is responsible for ensuring other.dtype == self.dtype
sv = self._get_join_target()
ov = other._get_join_target()
joined_ndarray, lidx, ridx = libjoin.left_join_indexer(sv, ov)
joined = self._from_join_target(joined_ndarray)
Reported by Pylint.
Line: 321
Column: 49
@final
def _left_indexer(
self: _IndexT, other: _IndexT
) -> tuple[ArrayLike, npt.NDArray[np.intp], npt.NDArray[np.intp]]:
# Caller is responsible for ensuring other.dtype == self.dtype
sv = self._get_join_target()
ov = other._get_join_target()
joined_ndarray, lidx, ridx = libjoin.left_join_indexer(sv, ov)
joined = self._from_join_target(joined_ndarray)
Reported by Pylint.
pandas/tests/arithmetic/test_timedelta64.py
382 issues
Line: 9
Column: 1
)
import numpy as np
import pytest
from pandas.errors import (
OutOfBoundsDatetime,
PerformanceWarning,
)
Reported by Pylint.
Line: 302
Column: 20
["-2H", "-4H", "-6H", "-8H", "-10H"], freq="-2H", name="x"
)
tm.assert_index_equal(result, exp)
assert result.freq == "-2H"
idx = TimedeltaIndex(["-2H", "-1H", "0H", "1H", "2H"], freq="H", name="x")
for result in [abs(idx), np.absolute(idx)]:
assert isinstance(result, TimedeltaIndex)
exp = TimedeltaIndex(["2H", "1H", "0H", "1H", "2H"], freq=None, name="x")
Reported by Pylint.
Line: 302
Column: 20
["-2H", "-4H", "-6H", "-8H", "-10H"], freq="-2H", name="x"
)
tm.assert_index_equal(result, exp)
assert result.freq == "-2H"
idx = TimedeltaIndex(["-2H", "-1H", "0H", "1H", "2H"], freq="H", name="x")
for result in [abs(idx), np.absolute(idx)]:
assert isinstance(result, TimedeltaIndex)
exp = TimedeltaIndex(["2H", "1H", "0H", "1H", "2H"], freq=None, name="x")
Reported by Pylint.
Line: 364
Column: 18
dti = pd.date_range("20130101", periods=3)
ts = Timestamp("20130101")
dt = ts.to_pydatetime()
dti_tz = pd.date_range("20130101", periods=3).tz_localize("US/Eastern")
ts_tz = Timestamp("20130101").tz_localize("US/Eastern")
ts_tz2 = Timestamp("20130101").tz_localize("CET")
dt_tz = ts_tz.to_pydatetime()
td = Timedelta("1 days")
Reported by Pylint.
Line: 364
Column: 18
dti = pd.date_range("20130101", periods=3)
ts = Timestamp("20130101")
dt = ts.to_pydatetime()
dti_tz = pd.date_range("20130101", periods=3).tz_localize("US/Eastern")
ts_tz = Timestamp("20130101").tz_localize("US/Eastern")
ts_tz2 = Timestamp("20130101").tz_localize("CET")
dt_tz = ts_tz.to_pydatetime()
td = Timedelta("1 days")
Reported by Pylint.
Line: 526
Column: 20
if freq == "D":
expected = pd.tseries.offsets.Day(1)
assert index.freq == expected
assert shifted.freq == expected
assert back.freq == expected
else: # freq == 'B'
assert index.freq == pd.tseries.offsets.BusinessDay(1)
assert shifted.freq is None
Reported by Pylint.
Line: 526
Column: 20
if freq == "D":
expected = pd.tseries.offsets.Day(1)
assert index.freq == expected
assert shifted.freq == expected
assert back.freq == expected
else: # freq == 'B'
assert index.freq == pd.tseries.offsets.BusinessDay(1)
assert shifted.freq is None
Reported by Pylint.
Line: 530
Column: 20
assert shifted.freq == expected
assert back.freq == expected
else: # freq == 'B'
assert index.freq == pd.tseries.offsets.BusinessDay(1)
assert shifted.freq is None
assert back.freq == pd.tseries.offsets.BusinessDay(1)
result = index - timedelta(1)
expected = index + timedelta(-1)
Reported by Pylint.
Line: 530
Column: 20
assert shifted.freq == expected
assert back.freq == expected
else: # freq == 'B'
assert index.freq == pd.tseries.offsets.BusinessDay(1)
assert shifted.freq is None
assert back.freq == pd.tseries.offsets.BusinessDay(1)
result = index - timedelta(1)
expected = index + timedelta(-1)
Reported by Pylint.
Line: 546
Column: 32
result3 = rng - np.timedelta64(100000000)
result4 = DatetimeIndex(s - offsets.Hour(1))
assert result1.freq == rng.freq
result1 = result1._with_freq(None)
tm.assert_index_equal(result1, result4)
assert result3.freq == rng.freq
result3 = result3._with_freq(None)
Reported by Pylint.
pandas/tests/frame/test_arithmetic.py
380 issues
Line: 7
Column: 1
import re
import numpy as np
import pytest
import pytz
import pandas.util._test_decorators as td
import pandas as pd
Reported by Pylint.
Line: 8
Column: 1
import numpy as np
import pytest
import pytz
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 36
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: 37
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
class DummyElement:
Reported by Pylint.
Line: 39
Column: 5
_MIN_ELEMENTS = expr._MIN_ELEMENTS
expr._MIN_ELEMENTS = request.param
yield request.param
expr._MIN_ELEMENTS = _MIN_ELEMENTS
class DummyElement:
def __init__(self, value, dtype):
self.value = value
Reported by Pylint.
Line: 56
Column: 29
def __repr__(self) -> str:
return str(self)
def astype(self, dtype, copy=False):
self.dtype = dtype
return self
def view(self, dtype):
return type(self)(self.value.view(dtype), dtype)
Reported by Pylint.
Line: 63
Column: 19
def view(self, dtype):
return type(self)(self.value.view(dtype), dtype)
def any(self, axis=None):
return bool(self.value)
# -------------------------------------------------------------------
# Comparisons
Reported by Pylint.
Line: 94
Column: 13
df = DataFrame(np.random.randn(6, 4), columns=list("ABCD"))
msg = "The truth value of a DataFrame is ambiguous"
with pytest.raises(ValueError, match=msg):
df in [None]
def test_comparison_invalid(self):
def check(df, df2):
for (x, y) in [(df, df2), (df2, df)]:
Reported by Pylint.
Line: 129
Column: 21
]
msg = "|".join(msgs)
with pytest.raises(TypeError, match=msg):
x >= y
with pytest.raises(TypeError, match=msg):
x > y
with pytest.raises(TypeError, match=msg):
x < y
with pytest.raises(TypeError, match=msg):
Reported by Pylint.
Line: 131
Column: 21
with pytest.raises(TypeError, match=msg):
x >= y
with pytest.raises(TypeError, match=msg):
x > y
with pytest.raises(TypeError, match=msg):
x < y
with pytest.raises(TypeError, match=msg):
x <= y
Reported by Pylint.
pandas/tests/io/json/test_pandas.py
379 issues
Line: 10
Column: 1
import sys
import numpy as np
import pytest
from pandas.compat import (
IS64,
PY310,
is_platform_windows,
Reported by Pylint.
Line: 1150
Column: 20
def test_datetime_tz(self):
# GH4377 df.to_json segfaults with non-ndarray blocks
tz_range = pd.date_range("20130101", periods=3, tz="US/Eastern")
tz_naive = tz_range.tz_convert("utc").tz_localize(None)
df = DataFrame({"A": tz_range, "B": pd.date_range("20130101", periods=3)})
df_naive = df.copy()
df_naive["A"] = tz_naive
Reported by Pylint.
Line: 1150
Column: 20
def test_datetime_tz(self):
# GH4377 df.to_json segfaults with non-ndarray blocks
tz_range = pd.date_range("20130101", periods=3, tz="US/Eastern")
tz_naive = tz_range.tz_convert("utc").tz_localize(None)
df = DataFrame({"A": tz_range, "B": pd.date_range("20130101", periods=3)})
df_naive = df.copy()
df_naive["A"] = tz_naive
Reported by Pylint.
Line: 56
Column: 9
class TestPandasContainer:
@pytest.fixture(autouse=True)
def setup(self):
self.categorical = _cat_frame.copy()
yield
@pytest.fixture
def datetime_series(self):
Reported by Pylint.
Line: 66
Column: 21
# since that doesn't round-trip, see GH#33711
ser = tm.makeTimeSeries()
ser.name = "ts"
ser.index = ser.index._with_freq(None)
return ser
@pytest.fixture
def datetime_frame(self):
# Same as usual datetime_frame, but with index freq set to None,
Reported by Pylint.
Line: 74
Column: 20
# Same as usual datetime_frame, but with index freq set to None,
# since that doesn't round-trip, see GH#33711
df = DataFrame(tm.getTimeSeriesData())
df.index = df.index._with_freq(None)
return df
def test_frame_double_encoded_labels(self, orient):
df = DataFrame(
[["a", "b"], ["c", "d"]],
Reported by Pylint.
Line: 126
Column: 3
# orient == "values" by default will write Timestamp objects out
# in milliseconds; these are internally stored in nanosecond,
# so divide to get where we need
# TODO: a to_epoch method would also solve; see GH 14772
expected.iloc[:, 0] = expected.iloc[:, 0].view(np.int64) // 1000000
elif orient == "split":
expected = df
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 172
Column: 3
and not dtype
and orient != "split"
):
# TODO: see what is causing roundtrip dtype loss
expected = expected.astype(np.int32)
assert_json_roundtrip_equal(result, expected, orient)
@pytest.mark.parametrize("dtype", [None, np.float64, int, "U3"])
Reported by Pylint.
Line: 188
Column: 3
dtype=dtype,
)
# TODO: do we even need to support U3 dtypes?
if numpy and dtype == "U3" and orient != "split":
request.node.add_marker(
pytest.mark.xfail(reason="Can't decode directly to array")
)
Reported by Pylint.
Line: 221
Column: 3
@pytest.mark.parametrize("convert_axes", [True, False])
@pytest.mark.parametrize("numpy", [True, False])
def test_roundtrip_categorical(self, request, orient, convert_axes, numpy):
# TODO: create a better frame to test with and improve coverage
if orient in ("index", "columns"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Can't have duplicate index values for orient '{orient}')"
)
Reported by Pylint.