The following issues were found
pandas/tests/indexes/datetimelike_/test_drop_duplicates.py
23 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
PeriodIndex,
Series,
date_range,
period_range,
timedelta_range,
Reported by Pylint.
Line: 29
Column: 24
# freq is reset except for PeriodIndex
assert idx_dup.freq is None
assert result.freq is None
expected = idx._with_freq(None)
else:
assert result.freq == expected.freq
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
PeriodIndex,
Series,
date_range,
period_range,
timedelta_range,
Reported by Pylint.
Line: 14
Column: 1
import pandas._testing as tm
class DropDuplicates:
def test_drop_duplicates_metadata(self, idx):
# GH#10115
result = idx.drop_duplicates()
tm.assert_index_equal(idx, result)
assert idx.freq == result.freq
Reported by Pylint.
Line: 15
Column: 5
class DropDuplicates:
def test_drop_duplicates_metadata(self, idx):
# GH#10115
result = idx.drop_duplicates()
tm.assert_index_equal(idx, result)
assert idx.freq == result.freq
Reported by Pylint.
Line: 15
Column: 5
class DropDuplicates:
def test_drop_duplicates_metadata(self, idx):
# GH#10115
result = idx.drop_duplicates()
tm.assert_index_equal(idx, result)
assert idx.freq == result.freq
Reported by Pylint.
Line: 19
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# GH#10115
result = idx.drop_duplicates()
tm.assert_index_equal(idx, result)
assert idx.freq == result.freq
idx_dup = idx.append(idx)
result = idx_dup.drop_duplicates()
expected = idx
Reported by Bandit.
Line: 27
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected = idx
if not isinstance(idx, PeriodIndex):
# freq is reset except for PeriodIndex
assert idx_dup.freq is None
assert result.freq is None
expected = idx._with_freq(None)
else:
assert result.freq == expected.freq
Reported by Bandit.
Line: 28
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if not isinstance(idx, PeriodIndex):
# freq is reset except for PeriodIndex
assert idx_dup.freq is None
assert result.freq is None
expected = idx._with_freq(None)
else:
assert result.freq == expected.freq
tm.assert_index_equal(result, expected)
Reported by Bandit.
Line: 31
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert result.freq is None
expected = idx._with_freq(None)
else:
assert result.freq == expected.freq
tm.assert_index_equal(result, expected)
@pytest.mark.parametrize(
"keep, expected, index",
Reported by Bandit.
pandas/tests/frame/methods/test_to_timestamp.py
23 issues
Line: 4
Column: 1
from datetime import timedelta
import numpy as np
import pytest
from pandas import (
DataFrame,
DatetimeIndex,
PeriodIndex,
Reported by Pylint.
Line: 1
Column: 1
from datetime import timedelta
import numpy as np
import pytest
from pandas import (
DataFrame,
DatetimeIndex,
PeriodIndex,
Reported by Pylint.
Line: 27
Column: 1
)
class TestToTimestamp:
def test_to_timestamp(self, frame_or_series):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
obj = DataFrame(
np.random.randn(len(index), K),
Reported by Pylint.
Line: 28
Column: 5
class TestToTimestamp:
def test_to_timestamp(self, frame_or_series):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
obj = DataFrame(
np.random.randn(len(index), K),
index=index,
Reported by Pylint.
Line: 28
Column: 5
class TestToTimestamp:
def test_to_timestamp(self, frame_or_series):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
obj = DataFrame(
np.random.randn(len(index), K),
index=index,
Reported by Pylint.
Line: 29
Column: 9
class TestToTimestamp:
def test_to_timestamp(self, frame_or_series):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
obj = DataFrame(
np.random.randn(len(index), K),
index=index,
columns=["A", "B", "C", "D", "E"],
Reported by Pylint.
Line: 46
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
tm.assert_index_equal(result.index, exp_index)
tm.assert_numpy_array_equal(result.values, obj.values)
if frame_or_series is Series:
assert result.name == "A"
exp_index = date_range("1/1/2001", end="1/1/2009", freq="AS-JAN")
result = obj.to_timestamp("D", "start")
tm.assert_index_equal(result.index, exp_index)
Reported by Bandit.
Line: 73
Column: 5
exp_index = exp_index + Timedelta(1, "s") - Timedelta(1, "ns")
tm.assert_index_equal(result.index, exp_index)
def test_to_timestamp_columns(self):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
df = DataFrame(
np.random.randn(len(index), K),
index=index,
Reported by Pylint.
Line: 73
Column: 5
exp_index = exp_index + Timedelta(1, "s") - Timedelta(1, "ns")
tm.assert_index_equal(result.index, exp_index)
def test_to_timestamp_columns(self):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
df = DataFrame(
np.random.randn(len(index), K),
index=index,
Reported by Pylint.
Line: 74
Column: 9
tm.assert_index_equal(result.index, exp_index)
def test_to_timestamp_columns(self):
K = 5
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
df = DataFrame(
np.random.randn(len(index), K),
index=index,
columns=["A", "B", "C", "D", "E"],
Reported by Pylint.
pandas/tests/frame/methods/test_get_numeric_data.py
23 issues
Line: 19
Column: 18
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = DataFrame({"A": [1, "2", 3.0]})
result = obj._get_numeric_data()
expected = DataFrame(index=[0, 1, 2], dtype=object)
tm.assert_frame_equal(result, expected)
def test_get_numeric_data(self):
Reported by Pylint.
Line: 57
Column: 18
index=np.arange(10),
)
result = df._get_numeric_data()
expected = df.loc[:, ["a", "b", "d", "e", "f"]]
tm.assert_frame_equal(result, expected)
only_obj = df.loc[:, ["c", "g"]]
result = only_obj._get_numeric_data()
Reported by Pylint.
Line: 62
Column: 18
tm.assert_frame_equal(result, expected)
only_obj = df.loc[:, ["c", "g"]]
result = only_obj._get_numeric_data()
expected = df.loc[:, []]
tm.assert_frame_equal(result, expected)
df = DataFrame.from_dict({"a": [1, 2], "b": ["foo", "bar"], "c": [np.pi, np.e]})
result = df._get_numeric_data()
Reported by Pylint.
Line: 67
Column: 18
tm.assert_frame_equal(result, expected)
df = DataFrame.from_dict({"a": [1, 2], "b": ["foo", "bar"], "c": [np.pi, np.e]})
result = df._get_numeric_data()
expected = DataFrame.from_dict({"a": [1, 2], "c": [np.pi, np.e]})
tm.assert_frame_equal(result, expected)
df = result.copy()
result = df._get_numeric_data()
Reported by Pylint.
Line: 72
Column: 18
tm.assert_frame_equal(result, expected)
df = result.copy()
result = df._get_numeric_data()
expected = df
tm.assert_frame_equal(result, expected)
def test_get_numeric_data_mixed_dtype(self):
# numeric and object columns
Reported by Pylint.
Line: 88
Column: 18
"e": [3.14, 0.577, 2.773],
}
)
result = df._get_numeric_data()
tm.assert_index_equal(result.columns, Index(["a", "b", "e"]))
def test_get_numeric_data_extension_dtype(self):
# GH#22290
df = DataFrame(
Reported by Pylint.
Line: 101
Column: 18
"D": IntervalArray.from_breaks(range(7)),
}
)
result = df._get_numeric_data()
expected = df.loc[:, ["A", "C"]]
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pandas as pd
from pandas import (
Categorical,
DataFrame,
Index,
Series,
Timestamp,
Reported by Pylint.
Line: 15
Column: 1
from pandas.core.arrays import IntervalArray
class TestGetNumericData:
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = DataFrame({"A": [1, "2", 3.0]})
result = obj._get_numeric_data()
expected = DataFrame(index=[0, 1, 2], dtype=object)
Reported by Pylint.
Line: 16
Column: 5
class TestGetNumericData:
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = DataFrame({"A": [1, "2", 3.0]})
result = obj._get_numeric_data()
expected = DataFrame(index=[0, 1, 2], dtype=object)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
pandas/core/accessor.py
23 issues
Line: 79
Column: 24
def _create_delegator_property(name):
def _getter(self):
return self._delegate_property_get(name)
def _setter(self, new_values):
return self._delegate_property_set(name, new_values)
_getter.__name__ = name
Reported by Pylint.
Line: 82
Column: 24
return self._delegate_property_get(name)
def _setter(self, new_values):
return self._delegate_property_set(name, new_values)
_getter.__name__ = name
_setter.__name__ = name
return property(
Reported by Pylint.
Line: 93
Column: 24
def _create_delegator_method(name):
def f(self, *args, **kwargs):
return self._delegate_method(name, *args, **kwargs)
f.__name__ = name
f.__doc__ = getattr(delegate, name).__doc__
return f
Reported by Pylint.
Line: 141
Column: 9
"""
def add_delegate_accessors(cls):
cls._add_delegate_accessors(delegate, accessors, typ, overwrite=overwrite)
return cls
return add_delegate_accessors
Reported by Pylint.
Line: 273
Column: 9
stacklevel=2,
)
setattr(cls, name, CachedAccessor(name, accessor))
cls._accessors.add(name)
return accessor
return decorator
Reported by Pylint.
Line: 14
Column: 1
from pandas.util._decorators import doc
class DirNamesMixin:
_accessors: set[str] = set()
_hidden_attrs: frozenset[str] = frozenset()
def _dir_deletions(self) -> set[str]:
"""
Reported by Pylint.
Line: 14
Column: 1
from pandas.util._decorators import doc
class DirNamesMixin:
_accessors: set[str] = set()
_hidden_attrs: frozenset[str] = frozenset()
def _dir_deletions(self) -> set[str]:
"""
Reported by Pylint.
Line: 38
Column: 9
-----
Only provide 'public' methods.
"""
rv = set(super().__dir__())
rv = (rv - self._dir_deletions()) | self._dir_additions()
return sorted(rv)
class PandasDelegate:
Reported by Pylint.
Line: 39
Column: 9
Only provide 'public' methods.
"""
rv = set(super().__dir__())
rv = (rv - self._dir_deletions()) | self._dir_additions()
return sorted(rv)
class PandasDelegate:
"""
Reported by Pylint.
Line: 43
Column: 1
return sorted(rv)
class PandasDelegate:
"""
Abstract base class for delegating methods/properties.
"""
def _delegate_property_get(self, name, *args, **kwargs):
Reported by Pylint.
pandas/tests/indexes/categorical/test_map.py
23 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalIndex,
Index,
Series,
)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalIndex,
Index,
Series,
)
Reported by Pylint.
Line: 13
Column: 1
import pandas._testing as tm
class TestMap:
@pytest.mark.parametrize(
"data, categories",
[
(list("abcbca"), list("cab")),
(pd.interval_range(0, 3).repeat(3), pd.interval_range(0, 3)),
Reported by Pylint.
Line: 21
Column: 5
(pd.interval_range(0, 3).repeat(3), pd.interval_range(0, 3)),
],
ids=["string", "interval"],
)
def test_map_str(self, data, categories, ordered):
# GH 31202 - override base class since we want to maintain categorical/ordered
index = CategoricalIndex(data, categories=categories, ordered=ordered)
result = index.map(str)
expected = CategoricalIndex(
Reported by Pylint.
Line: 21
Column: 5
(pd.interval_range(0, 3).repeat(3), pd.interval_range(0, 3)),
],
ids=["string", "interval"],
)
def test_map_str(self, data, categories, ordered):
# GH 31202 - override base class since we want to maintain categorical/ordered
index = CategoricalIndex(data, categories=categories, ordered=ordered)
result = index.map(str)
expected = CategoricalIndex(
Reported by Pylint.
Line: 31
Column: 5
)
tm.assert_index_equal(result, expected)
def test_map(self):
ci = CategoricalIndex(list("ABABC"), categories=list("CBA"), ordered=True)
result = ci.map(lambda x: x.lower())
exp = CategoricalIndex(list("ababc"), categories=list("cba"), ordered=True)
tm.assert_index_equal(result, exp)
Reported by Pylint.
Line: 31
Column: 5
)
tm.assert_index_equal(result, expected)
def test_map(self):
ci = CategoricalIndex(list("ABABC"), categories=list("CBA"), ordered=True)
result = ci.map(lambda x: x.lower())
exp = CategoricalIndex(list("ababc"), categories=list("cba"), ordered=True)
tm.assert_index_equal(result, exp)
Reported by Pylint.
Line: 32
Column: 9
tm.assert_index_equal(result, expected)
def test_map(self):
ci = CategoricalIndex(list("ABABC"), categories=list("CBA"), ordered=True)
result = ci.map(lambda x: x.lower())
exp = CategoricalIndex(list("ababc"), categories=list("cba"), ordered=True)
tm.assert_index_equal(result, exp)
ci = CategoricalIndex(
Reported by Pylint.
Line: 37
Column: 9
exp = CategoricalIndex(list("ababc"), categories=list("cba"), ordered=True)
tm.assert_index_equal(result, exp)
ci = CategoricalIndex(
list("ABABC"), categories=list("BAC"), ordered=False, name="XXX"
)
result = ci.map(lambda x: x.lower())
exp = CategoricalIndex(
list("ababc"), categories=list("bac"), ordered=False, name="XXX"
Reported by Pylint.
Line: 52
Column: 9
)
# change categories dtype
ci = CategoricalIndex(list("ABABC"), categories=list("BAC"), ordered=False)
def f(x):
return {"A": 10, "B": 20, "C": 30}.get(x)
result = ci.map(f)
Reported by Pylint.
pandas/core/dtypes/missing.py
23 issues
Line: 11
Column: 1
from pandas._config import get_option
from pandas._libs import lib
import pandas._libs.missing as libmissing
from pandas._libs.tslibs import (
NaT,
Period,
iNaT,
Reported by Pylint.
Line: 12
Column: 1
from pandas._config import get_option
from pandas._libs import lib
import pandas._libs.missing as libmissing
from pandas._libs.tslibs import (
NaT,
Period,
iNaT,
)
Reported by Pylint.
Line: 12
Column: 1
from pandas._config import get_option
from pandas._libs import lib
import pandas._libs.missing as libmissing
from pandas._libs.tslibs import (
NaT,
Period,
iNaT,
)
Reported by Pylint.
Line: 173
Column: 30
elif isinstance(obj, (np.ndarray, ABCExtensionArray)):
return _isna_array(obj, inf_as_na=inf_as_na)
elif isinstance(obj, (ABCSeries, ABCIndex)):
result = _isna_array(obj._values, inf_as_na=inf_as_na)
# box
if isinstance(obj, ABCSeries):
result = obj._constructor(
result, index=obj.index, name=obj.name, copy=False
)
Reported by Pylint.
Line: 176
Column: 22
result = _isna_array(obj._values, inf_as_na=inf_as_na)
# box
if isinstance(obj, ABCSeries):
result = obj._constructor(
result, index=obj.index, name=obj.name, copy=False
)
return result
elif isinstance(obj, ABCDataFrame):
return obj.isna()
Reported by Pylint.
Line: 434
Column: 3
elif needs_i8_conversion(left.dtype):
return _array_equivalent_datetimelike(left, right)
elif is_string_dtype(left.dtype):
# TODO: fastpath for pandas' StringDtype
return _array_equivalent_object(left, right, strict_nan)
else:
return np.array_equal(left, right)
# Slow path when we allow comparing different dtypes.
Reported by Pylint.
Line: 144
Column: 1
isnull = isna
def _isna(obj, inf_as_na: bool = False):
"""
Detect missing values, treating None, NaN or NA as null. Infinite
values will also be treated as null if inf_as_na is True.
Parameters
Reported by Pylint.
Line: 161
Column: 9
boolean ndarray or boolean
"""
if is_scalar(obj):
if inf_as_na:
return libmissing.checknull_old(obj)
else:
return libmissing.checknull(obj)
# hack (for now) because MI registers as ndarray
elif isinstance(obj, ABCMultiIndex):
Reported by Pylint.
Line: 381
Column: 1
return True
def array_equivalent(
left, right, strict_nan: bool = False, dtype_equal: bool = False
) -> bool:
"""
True if two arrays, left and right, have equal non-NaN elements, and NaNs
in corresponding locations. False otherwise. It is assumed that left and
Reported by Pylint.
Line: 381
Column: 1
return True
def array_equivalent(
left, right, strict_nan: bool = False, dtype_equal: bool = False
) -> bool:
"""
True if two arrays, left and right, have equal non-NaN elements, and NaNs
in corresponding locations. False otherwise. It is assumed that left and
Reported by Pylint.
pandas/io/json/_normalize.py
23 issues
Line: 18
Column: 1
import numpy as np
from pandas._libs.writers import convert_json_to_lines
from pandas._typing import Scalar
from pandas.util._decorators import deprecate
import pandas as pd
from pandas import DataFrame
Reported by Pylint.
Line: 18
Column: 1
import numpy as np
from pandas._libs.writers import convert_json_to_lines
from pandas._typing import Scalar
from pandas.util._decorators import deprecate
import pandas as pd
from pandas import DataFrame
Reported by Pylint.
Line: 461
Column: 3
# deeply nested structures:
# {VeryLong: { b: 1,c:2}} -> {VeryLong.b:1 ,VeryLong.c:@}
#
# TODO: handle record value which are lists, at least error
# reasonably
data = nested_to_record(data, sep=sep, max_level=max_level)
return DataFrame(data)
elif not isinstance(record_path, list):
record_path = [record_path]
Reported by Pylint.
Line: 1
Column: 1
# ---------------------------------------------------------------------
# JSON normalization routines
from __future__ import annotations
from collections import (
abc,
defaultdict,
)
import copy
Reported by Pylint.
Line: 26
Column: 1
from pandas import DataFrame
def convert_to_line_delimits(s: str) -> str:
"""
Helper function that converts JSON lists to line delimited JSON.
"""
# Determine we have a JSON list to turn to lines otherwise just return the
# json object, only lists can
Reported by Pylint.
Line: 39
Column: 1
return convert_json_to_lines(s)
def nested_to_record(
ds,
prefix: str = "",
sep: str = ".",
level: int = 0,
max_level: int | None = None,
Reported by Pylint.
Line: 90
Column: 9
ds = [ds]
singleton = True
new_ds = []
for d in ds:
new_d = copy.deepcopy(d)
for k, v in d.items():
# each key gets renamed with prefix
if not isinstance(k, str):
k = str(k)
Reported by Pylint.
Line: 92
Column: 16
new_ds = []
for d in ds:
new_d = copy.deepcopy(d)
for k, v in d.items():
# each key gets renamed with prefix
if not isinstance(k, str):
k = str(k)
if level == 0:
newkey = k
Reported by Pylint.
Line: 105
Column: 13
# current dict level < maximum level provided and
# only dicts gets recurse-flattened
# only at level>1 do we rename the rest of the keys
if not isinstance(v, dict) or (
max_level is not None and level >= max_level
):
if level != 0: # so we skip copying for top level, common case
v = new_d.pop(k)
new_d[newkey] = v
Reported by Pylint.
Line: 109
Column: 21
max_level is not None and level >= max_level
):
if level != 0: # so we skip copying for top level, common case
v = new_d.pop(k)
new_d[newkey] = v
continue
else:
v = new_d.pop(k)
new_d.update(nested_to_record(v, newkey, sep, level + 1, max_level))
Reported by Pylint.
pandas/core/common.py
23 issues
Line: 30
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._typing import (
AnyArrayLike,
ArrayLike,
NpDtype,
RandomState,
Reported by Pylint.
Line: 404
Column: 55
@overload
def random_state(
state: int | ArrayLike | np.random.BitGenerator | np.random.RandomState | None,
) -> np.random.RandomState:
...
def random_state(state: RandomState | None = None):
Reported by Pylint.
Line: 405
Column: 6
@overload
def random_state(
state: int | ArrayLike | np.random.BitGenerator | np.random.RandomState | None,
) -> np.random.RandomState:
...
def random_state(state: RandomState | None = None):
"""
Reported by Pylint.
Line: 451
Column: 16
# Sequence[Sequence[Union[bool, int]]], Sequence[Sequence[Sequence[Union[bool,
# int]]]], Sequence[Sequence[Sequence[Sequence[Union[bool, int]]]]]]],
# BitGenerator]"
return np.random.RandomState(state) # type: ignore[arg-type]
elif isinstance(state, np.random.RandomState):
return state
elif isinstance(state, np.random.Generator):
return state
elif state is None:
Reported by Pylint.
Line: 452
Column: 28
# int]]]], Sequence[Sequence[Sequence[Sequence[Union[bool, int]]]]]]],
# BitGenerator]"
return np.random.RandomState(state) # type: ignore[arg-type]
elif isinstance(state, np.random.RandomState):
return state
elif isinstance(state, np.random.Generator):
return state
elif state is None:
return np.random
Reported by Pylint.
Line: 233
Column: 16
elif isinstance(values, ABCIndex):
# error: Incompatible return value type (got "Union[ExtensionArray, ndarray]",
# expected "ndarray")
return values._values # type: ignore[return-value]
# error: Non-overlapping container check (element type: "Union[str, dtype[Any],
# None]", container item type: "type")
if isinstance(values, list) and dtype in [ # type: ignore[comparison-overlap]
np.object_,
Reported by Pylint.
Line: 318
Column: 3
return [isinstance(k, slice) and not is_null_slice(k) for k in line]
# TODO: used only once in indexing; belongs elsewhere?
def is_full_slice(obj, line: int) -> bool:
"""
We have a full length slice.
"""
return (
Reported by Pylint.
Line: 59
Column: 1
from pandas import Index
class SettingWithCopyError(ValueError):
pass
class SettingWithCopyWarning(Warning):
pass
Reported by Pylint.
Line: 63
Column: 1
pass
class SettingWithCopyWarning(Warning):
pass
def flatten(line):
"""
Reported by Pylint.
Line: 91
Column: 1
yield element
def consensus_name_attr(objs):
name = objs[0].name
for obj in objs[1:]:
try:
if obj.name != name:
name = None
Reported by Pylint.
pandas/tests/frame/methods/test_tz_localize.py
23 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
date_range,
)
import pandas._testing as tm
Reported by Pylint.
Line: 24
Column: 40
obj = obj["a"]
result = obj.tz_localize("utc")
expected = DataFrame({"a": 1}, rng.tz_localize("UTC"))
if frame_or_series is not DataFrame:
expected = expected["a"]
assert result.index.tz.zone == "UTC"
tm.assert_equal(result, expected)
Reported by Pylint.
Line: 24
Column: 40
obj = obj["a"]
result = obj.tz_localize("utc")
expected = DataFrame({"a": 1}, rng.tz_localize("UTC"))
if frame_or_series is not DataFrame:
expected = expected["a"]
assert result.index.tz.zone == "UTC"
tm.assert_equal(result, expected)
Reported by Pylint.
Line: 40
Column: 40
result = df.tz_localize("utc", axis=1)
assert result.columns.tz.zone == "UTC"
expected = DataFrame({"a": 1}, rng.tz_localize("UTC"))
tm.assert_frame_equal(result, expected.T)
def test_tz_localize_naive(self, frame_or_series):
Reported by Pylint.
Line: 40
Column: 40
result = df.tz_localize("utc", axis=1)
assert result.columns.tz.zone == "UTC"
expected = DataFrame({"a": 1}, rng.tz_localize("UTC"))
tm.assert_frame_equal(result, expected.T)
def test_tz_localize_naive(self, frame_or_series):
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
date_range,
)
import pandas._testing as tm
Reported by Pylint.
Line: 12
Column: 1
import pandas._testing as tm
class TestTZLocalize:
# See also:
# test_tz_convert_and_localize in test_tz_convert
def test_tz_localize(self, frame_or_series):
rng = date_range("1/1/2011", periods=100, freq="H")
Reported by Pylint.
Line: 16
Column: 5
# See also:
# test_tz_convert_and_localize in test_tz_convert
def test_tz_localize(self, frame_or_series):
rng = date_range("1/1/2011", periods=100, freq="H")
obj = DataFrame({"a": 1}, index=rng)
if frame_or_series is not DataFrame:
obj = obj["a"]
Reported by Pylint.
Line: 16
Column: 5
# See also:
# test_tz_convert_and_localize in test_tz_convert
def test_tz_localize(self, frame_or_series):
rng = date_range("1/1/2011", periods=100, freq="H")
obj = DataFrame({"a": 1}, index=rng)
if frame_or_series is not DataFrame:
obj = obj["a"]
Reported by Pylint.
Line: 28
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if frame_or_series is not DataFrame:
expected = expected["a"]
assert result.index.tz.zone == "UTC"
tm.assert_equal(result, expected)
def test_tz_localize_axis1(self):
rng = date_range("1/1/2011", periods=100, freq="H")
Reported by Bandit.
pandas/tests/frame/methods/test_explode.py
23 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
def test_error():
df = pd.DataFrame(
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
def test_error():
df = pd.DataFrame(
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
def test_error():
df = pd.DataFrame(
{"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
)
with pytest.raises(
ValueError, match="column must be a scalar, tuple, or list thereof"
Reported by Pylint.
Line: 9
Column: 5
def test_error():
df = pd.DataFrame(
{"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
)
with pytest.raises(
ValueError, match="column must be a scalar, tuple, or list thereof"
):
Reported by Pylint.
Line: 39
Column: 1
(
list("AC"),
"columns must have matching element counts",
),
],
)
def test_error_multi_columns(input_subset, error_message):
# GH 39240
df = pd.DataFrame(
Reported by Pylint.
Line: 44
Column: 5
)
def test_error_multi_columns(input_subset, error_message):
# GH 39240
df = pd.DataFrame(
{
"A": [[0, 1, 2], np.nan, [], (3, 4)],
"B": 1,
"C": [["a", "b", "c"], "foo", [], ["d", "e", "f"]],
},
Reported by Pylint.
Line: 56
Column: 1
df.explode(input_subset)
def test_basic():
df = pd.DataFrame(
{"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
)
result = df.explode("A")
expected = pd.DataFrame(
Reported by Pylint.
Line: 57
Column: 5
def test_basic():
df = pd.DataFrame(
{"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
)
result = df.explode("A")
expected = pd.DataFrame(
{
Reported by Pylint.
Line: 72
Column: 1
tm.assert_frame_equal(result, expected)
def test_multi_index_rows():
df = pd.DataFrame(
{"A": np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), "B": 1},
index=pd.MultiIndex.from_tuples([("a", 1), ("a", 2), ("b", 1), ("b", 2)]),
)
Reported by Pylint.
Line: 73
Column: 5
def test_multi_index_rows():
df = pd.DataFrame(
{"A": np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), "B": 1},
index=pd.MultiIndex.from_tuples([("a", 1), ("a", 2), ("b", 1), ("b", 2)]),
)
result = df.explode("A")
Reported by Pylint.