The following issues were found
asv_bench/benchmarks/strings.py
156 issues
Line: 5
Column: 1
import numpy as np
from pandas import (
Categorical,
DataFrame,
Series,
)
Reported by Pylint.
Line: 11
Column: 1
Series,
)
from .pandas_vb_common import tm
class Dtypes:
params = ["str", "string[python]", "string[pyarrow]"]
param_names = ["dtype"]
Reported by Pylint.
Line: 20
Column: 13
def setup(self, dtype):
try:
self.s = Series(tm.makeStringIndex(10 ** 5), dtype=dtype)
except ImportError:
raise NotImplementedError
class Construction:
Reported by Pylint.
Line: 22
Column: 13
try:
self.s = Series(tm.makeStringIndex(10 ** 5), dtype=dtype)
except ImportError:
raise NotImplementedError
class Construction:
params = ["str", "string"]
Reported by Pylint.
Line: 30
Column: 21
params = ["str", "string"]
param_names = ["dtype"]
def setup(self, dtype):
self.series_arr = tm.rands_array(nchars=10, size=10 ** 5)
self.frame_arr = self.series_arr.reshape((50_000, 2)).copy()
# GH37371. Testing construction of string series/frames from ExtensionArrays
self.series_cat_arr = Categorical(self.series_arr)
Reported by Pylint.
Line: 31
Column: 9
param_names = ["dtype"]
def setup(self, dtype):
self.series_arr = tm.rands_array(nchars=10, size=10 ** 5)
self.frame_arr = self.series_arr.reshape((50_000, 2)).copy()
# GH37371. Testing construction of string series/frames from ExtensionArrays
self.series_cat_arr = Categorical(self.series_arr)
self.frame_cat_arr = Categorical(self.frame_arr)
Reported by Pylint.
Line: 32
Column: 9
def setup(self, dtype):
self.series_arr = tm.rands_array(nchars=10, size=10 ** 5)
self.frame_arr = self.series_arr.reshape((50_000, 2)).copy()
# GH37371. Testing construction of string series/frames from ExtensionArrays
self.series_cat_arr = Categorical(self.series_arr)
self.frame_cat_arr = Categorical(self.frame_arr)
Reported by Pylint.
Line: 35
Column: 9
self.frame_arr = self.series_arr.reshape((50_000, 2)).copy()
# GH37371. Testing construction of string series/frames from ExtensionArrays
self.series_cat_arr = Categorical(self.series_arr)
self.frame_cat_arr = Categorical(self.frame_arr)
def time_series_construction(self, dtype):
Series(self.series_arr, dtype=dtype)
Reported by Pylint.
Line: 36
Column: 9
# GH37371. Testing construction of string series/frames from ExtensionArrays
self.series_cat_arr = Categorical(self.series_arr)
self.frame_cat_arr = Categorical(self.frame_arr)
def time_series_construction(self, dtype):
Series(self.series_arr, dtype=dtype)
def peakmem_series_construction(self, dtype):
Reported by Pylint.
Line: 64
Column: 27
class Methods(Dtypes):
def time_center(self, dtype):
self.s.str.center(100)
def time_count(self, dtype):
self.s.str.count("A")
Reported by Pylint.
pandas/tests/indexes/period/test_constructors.py
155 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas._libs.tslibs.period import IncompatibleFrequency
from pandas.core.dtypes.dtypes import PeriodDtype
from pandas import (
Index,
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import pytest
from pandas._libs.tslibs.period import IncompatibleFrequency
from pandas.core.dtypes.dtypes import PeriodDtype
from pandas import (
Index,
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import pytest
from pandas._libs.tslibs.period import IncompatibleFrequency
from pandas.core.dtypes.dtypes import PeriodDtype
from pandas import (
Index,
Reported by Pylint.
Line: 127
Column: 31
pindex = PeriodIndex(year=years, quarter=quarters)
tm.assert_index_equal(pindex.year, Index(years))
tm.assert_index_equal(pindex.quarter, Index(quarters))
def test_constructor_invalid_quarters(self):
msg = "Quarter must be 1 <= q <= 4"
with pytest.raises(ValueError, match=msg):
Reported by Pylint.
Line: 128
Column: 31
pindex = PeriodIndex(year=years, quarter=quarters)
tm.assert_index_equal(pindex.year, Index(years))
tm.assert_index_equal(pindex.quarter, Index(quarters))
def test_constructor_invalid_quarters(self):
msg = "Quarter must be 1 <= q <= 4"
with pytest.raises(ValueError, match=msg):
PeriodIndex(year=range(2000, 2004), quarter=list(range(4)), freq="Q-DEC")
Reported by Pylint.
Line: 408
Column: 20
def test_constructor_freq_mult_dti_compat(self, mult, freq):
freqstr = str(mult) + freq
pidx = period_range(start="2014-04-01", freq=freqstr, periods=10)
expected = date_range(start="2014-04-01", freq=freqstr, periods=10).to_period(
freqstr
)
tm.assert_index_equal(pidx, expected)
def test_constructor_freq_combined(self):
Reported by Pylint.
Line: 408
Column: 20
def test_constructor_freq_mult_dti_compat(self, mult, freq):
freqstr = str(mult) + freq
pidx = period_range(start="2014-04-01", freq=freqstr, periods=10)
expected = date_range(start="2014-04-01", freq=freqstr, periods=10).to_period(
freqstr
)
tm.assert_index_equal(pidx, expected)
def test_constructor_freq_combined(self):
Reported by Pylint.
Line: 47
Column: 61
tm.assert_index_equal(result, expected)
@pytest.mark.parametrize(
"values_constructor", [list, np.array, PeriodIndex, PeriodArray._from_sequence]
)
def test_index_object_dtype(self, values_constructor):
# Index(periods, dtype=object) is an Index (not an PeriodIndex)
periods = [
Period("2011-01", freq="M"),
Reported by Pylint.
Line: 195
Column: 20
# https://github.com/pandas-dev/pandas/issues/23438
data = date_range("2017", periods=4, freq="M")
if box is None:
data = data._values
elif box == "series":
data = Series(data)
result = PeriodIndex(data, freq="D")
expected = PeriodIndex(
Reported by Pylint.
Line: 324
Column: 13
idx = period_range("2007-01", name="p", periods=2, freq="M")
with pytest.raises(AssertionError, match="<class .*PeriodIndex'>"):
idx._simple_new(idx, name="p")
result = idx._simple_new(idx._data, name="p")
tm.assert_index_equal(result, idx)
msg = "Should be numpy array of type i8"
Reported by Pylint.
asv_bench/benchmarks/tslibs/timestamp.py
154 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytz
from pandas import Timestamp
from .tslib import _tzs
Reported by Pylint.
Line: 6
Column: 1
import numpy as np
import pytz
from pandas import Timestamp
from .tslib import _tzs
class TimestampConstruction:
Reported by Pylint.
Line: 8
Column: 1
from pandas import Timestamp
from .tslib import _tzs
class TimestampConstruction:
def setup(self):
self.npdatetime64 = np.datetime64("2020-01-01 00:00:00")
Reported by Pylint.
Line: 13
Column: 9
class TimestampConstruction:
def setup(self):
self.npdatetime64 = np.datetime64("2020-01-01 00:00:00")
self.dttime_unaware = datetime(2020, 1, 1, 0, 0, 0)
self.dttime_aware = datetime(2020, 1, 1, 0, 0, 0, 0, pytz.UTC)
self.ts = Timestamp("2020-01-01 00:00:00")
def time_parse_iso8601_no_tz(self):
Reported by Pylint.
Line: 14
Column: 9
class TimestampConstruction:
def setup(self):
self.npdatetime64 = np.datetime64("2020-01-01 00:00:00")
self.dttime_unaware = datetime(2020, 1, 1, 0, 0, 0)
self.dttime_aware = datetime(2020, 1, 1, 0, 0, 0, 0, pytz.UTC)
self.ts = Timestamp("2020-01-01 00:00:00")
def time_parse_iso8601_no_tz(self):
Timestamp("2017-08-25 08:16:14")
Reported by Pylint.
Line: 15
Column: 9
def setup(self):
self.npdatetime64 = np.datetime64("2020-01-01 00:00:00")
self.dttime_unaware = datetime(2020, 1, 1, 0, 0, 0)
self.dttime_aware = datetime(2020, 1, 1, 0, 0, 0, 0, pytz.UTC)
self.ts = Timestamp("2020-01-01 00:00:00")
def time_parse_iso8601_no_tz(self):
Timestamp("2017-08-25 08:16:14")
Reported by Pylint.
Line: 16
Column: 9
self.npdatetime64 = np.datetime64("2020-01-01 00:00:00")
self.dttime_unaware = datetime(2020, 1, 1, 0, 0, 0)
self.dttime_aware = datetime(2020, 1, 1, 0, 0, 0, 0, pytz.UTC)
self.ts = Timestamp("2020-01-01 00:00:00")
def time_parse_iso8601_no_tz(self):
Timestamp("2017-08-25 08:16:14")
def time_parse_iso8601_tz(self):
Reported by Pylint.
Line: 58
Column: 9
param_names = ["tz", "freq"]
def setup(self, tz, freq):
self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz, freq=freq)
def time_tz(self, tz, freq):
self.ts.tz
def time_dayofweek(self, tz, freq):
Reported by Pylint.
Line: 60
Column: 23
def setup(self, tz, freq):
self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz, freq=freq)
def time_tz(self, tz, freq):
self.ts.tz
def time_dayofweek(self, tz, freq):
self.ts.dayofweek
Reported by Pylint.
Line: 60
Column: 27
def setup(self, tz, freq):
self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz, freq=freq)
def time_tz(self, tz, freq):
self.ts.tz
def time_dayofweek(self, tz, freq):
self.ts.dayofweek
Reported by Pylint.
asv_bench/benchmarks/io/csv.py
154 issues
Line: 10
Column: 1
import numpy as np
from pandas import (
Categorical,
DataFrame,
date_range,
read_csv,
to_datetime,
Reported by Pylint.
Line: 18
Column: 1
to_datetime,
)
from ..pandas_vb_common import (
BaseIO,
tm,
)
Reported by Pylint.
Line: 499
Column: 1
to_datetime(df["date"], cache=cache_dates, format="%d-%m-%Y")
from ..pandas_vb_common import setup # noqa: F401 isort:skip
Reported by Pylint.
Line: 51
Column: 9
)
mixed_frame.loc[30:500, "float"] = np.nan
data = {"wide": wide_frame, "long": long_frame, "mixed": mixed_frame}
self.df = data[kind]
def time_frame(self, kind):
self.df.to_csv(self.fname)
Reported by Pylint.
Line: 53
Column: 26
data = {"wide": wide_frame, "long": long_frame, "mixed": mixed_frame}
self.df = data[kind]
def time_frame(self, kind):
self.df.to_csv(self.fname)
class ToCSVDatetime(BaseIO):
Reported by Pylint.
Line: 63
Column: 9
def setup(self):
rng = date_range("1/1/2000", periods=1000)
self.data = DataFrame(rng, index=rng)
def time_frame_date_formatting(self):
self.data.to_csv(self.fname, date_format="%Y%m%d")
Reported by Pylint.
Line: 79
Column: 9
def setup(self, obs):
d = "2018-11-29"
dt = "2018-11-26 11:18:27.0"
self.data = DataFrame(
{
"dt": [np.datetime64(dt)] * obs,
"d": [np.datetime64(d)] * obs,
"r": [np.random.uniform()] * obs,
}
Reported by Pylint.
Line: 87
Column: 26
}
)
def time_frame(self, obs):
self.data.to_csv(self.fname)
class ToCSVIndexes(BaseIO):
Reported by Pylint.
Line: 115
Column: 9
# more rows
HEAD_ROW_MULTIPLIER = 10
self.df_standard_index = self._create_df(ROWS, COLS)
self.df_custom_index_then_head = (
self._create_df(ROWS * HEAD_ROW_MULTIPLIER, COLS)
.set_index(["index1", "index2", "index3"])
.head(ROWS)
Reported by Pylint.
Line: 117
Column: 9
self.df_standard_index = self._create_df(ROWS, COLS)
self.df_custom_index_then_head = (
self._create_df(ROWS * HEAD_ROW_MULTIPLIER, COLS)
.set_index(["index1", "index2", "index3"])
.head(ROWS)
)
Reported by Pylint.
pandas/tests/indexes/test_setops.py
153 issues
Line: 9
Column: 1
import operator
import numpy as np
import pytest
from pandas.core.dtypes.cast import find_common_type
from pandas import (
CategoricalIndex,
Reported by Pylint.
Line: 126
Column: 3
assert result.name == names[2]
# Testing name retention
# TODO: pin down desired dtype; do we want it to be commutative?
result = a.intersection(b)
assert result.name == names[2]
def test_dunder_inplace_setops_deprecated(index):
Reported by Pylint.
Line: 426
Column: 60
expected = index[:0]
tm.assert_index_equal(result, expected, exact=True)
def test_difference_name_retention_equals(self, index, sort, names):
if isinstance(index, MultiIndex):
names = [[x] * index.nlevels for x in names]
index = index.rename(names[0])
other = index.rename(names[1])
Reported by Pylint.
Line: 772
Column: 3
@pytest.mark.xfail(reason="Not implemented")
@pytest.mark.parametrize("opname", ["difference", "symmetric_difference"])
def test_difference_incomparable_true(self, opname):
# TODO: decide on True behaviour
# # sort=True, raises
a = Index([3, Timestamp("2000"), 1])
b = Index([2, Timestamp("1999"), 1])
op = operator.methodcaller(opname, b, sort=True)
Reported by Pylint.
Line: 38
Column: 1
]
def test_union_same_types(index):
# Union with a non-unique, non-monotonic index raises error
# Only needed for bool index factory
idx1 = index.sort_values()
idx2 = index.sort_values()
assert idx1.union(idx2).dtype == idx1.dtype
Reported by Pylint.
Line: 43
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# Only needed for bool index factory
idx1 = index.sort_values()
idx2 = index.sort_values()
assert idx1.union(idx2).dtype == idx1.dtype
def test_union_different_types(index_flat, index_flat2):
# This test only considers combinations of indices
# GH 23525
Reported by Bandit.
Line: 46
Column: 1
assert idx1.union(idx2).dtype == idx1.dtype
def test_union_different_types(index_flat, index_flat2):
# This test only considers combinations of indices
# GH 23525
idx1 = index_flat
idx2 = index_flat2
Reported by Pylint.
Line: 67
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
res2 = idx2.union(idx1)
if any_uint64 and (idx1_signed or idx2_signed):
assert res1.dtype == np.dtype("O")
assert res2.dtype == np.dtype("O")
else:
assert res1.dtype == common_dtype
assert res2.dtype == common_dtype
Reported by Bandit.
Line: 68
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if any_uint64 and (idx1_signed or idx2_signed):
assert res1.dtype == np.dtype("O")
assert res2.dtype == np.dtype("O")
else:
assert res1.dtype == common_dtype
assert res2.dtype == common_dtype
Reported by Bandit.
Line: 70
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert res1.dtype == np.dtype("O")
assert res2.dtype == np.dtype("O")
else:
assert res1.dtype == common_dtype
assert res2.dtype == common_dtype
@pytest.mark.parametrize(
"idx_fact1,idx_fact2",
Reported by Bandit.
pandas/tests/frame/indexing/test_where.py
153 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytest
from pandas.core.dtypes.common import is_scalar
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 44
Column: 30
class TestDataFrameIndexingWhere:
def test_where_get(self, where_frame, float_string_frame):
def _check_get(df, cond, check_dtypes=True):
other1 = _safe_add(df)
rs = df.where(cond, other1)
rs2 = df.where(cond.values, other1)
for k, v in rs.items():
Reported by Pylint.
Line: 63
Column: 17
if df is float_string_frame:
msg = "'>' not supported between instances of 'str' and 'int'"
with pytest.raises(TypeError, match=msg):
df > 0
return
cond = df > 0
_check_get(df, cond)
def test_where_upcasting(self):
Reported by Pylint.
Line: 94
Column: 36
tm.assert_series_equal(result, expected)
def test_where_alignment(self, where_frame, float_string_frame):
# aligning
def _check_align(df, cond, other, check_dtypes=True):
rs = df.where(cond, other)
for i, k in enumerate(rs.columns):
result = rs[k]
Reported by Pylint.
Line: 128
Column: 17
if df is float_string_frame:
msg = "'>' not supported between instances of 'str' and 'int'"
with pytest.raises(TypeError, match=msg):
df > 0
return
# other is a frame
cond = (df > 0)[1:]
_check_align(df, cond, _safe_add(df))
Reported by Pylint.
Line: 165
Column: 30
with pytest.raises(ValueError, match=msg):
df.mask(0)
def test_where_set(self, where_frame, float_string_frame):
# where inplace
def _check_set(df, cond, check_dtypes=True):
dfi = df.copy()
econd = cond.reindex_like(df).fillna(True)
Reported by Pylint.
Line: 188
Column: 17
if df is float_string_frame:
msg = "'>' not supported between instances of 'str' and 'int'"
with pytest.raises(TypeError, match=msg):
df > 0
return
cond = df > 0
_check_set(df, cond)
Reported by Pylint.
Line: 377
Column: 13
stamp = datetime(2013, 1, 3)
msg = "'>' not supported between instances of 'float' and 'datetime.datetime'"
with pytest.raises(TypeError, match=msg):
df > stamp
result = df[df.iloc[:, :-1] > stamp]
expected = df.copy()
expected.loc[[0, 1], "A"] = np.nan
Reported by Pylint.
Line: 674
Column: 3
mask = np.ones(df.shape, dtype=bool)
mask[1, :] = False
# TODO: ideally we would get Int64 instead of object
result = df.where(mask, ser, axis=0)
expected = DataFrame({"A": [1, pd.NA, 3], "B": [4, pd.NA, 6]}).astype(object)
tm.assert_frame_equal(result, expected)
ser2 = Series(arr[:2], index=["A", "B"])
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import numpy as np
import pytest
from pandas.core.dtypes.common import is_scalar
import pandas as pd
from pandas import (
Reported by Pylint.
pandas/tests/series/methods/test_interpolate.py
153 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Index,
MultiIndex,
Reported by Pylint.
Line: 81
Column: 49
class TestSeriesInterpolateData:
def test_interpolate(self, datetime_series, string_series):
ts = Series(np.arange(len(datetime_series), dtype=float), datetime_series.index)
ts_copy = ts.copy()
ts_copy[5:10] = np.NaN
Reported by Pylint.
Line: 135
Column: 9
).astype(float)
interp_s = ser.reindex(new_index).interpolate(method="pchip")
# does not blow up, GH5977
interp_s[49:51]
@td.skip_if_no_scipy
def test_interpolate_akima(self):
ser = Series([10, 11, 12, 13])
Reported by Pylint.
Line: 321
Column: 58
tm.assert_series_equal(result, expected)
@pytest.mark.parametrize("limit", [-1, 0])
def test_interpolate_invalid_nonpositive_limit(self, nontemporal_method, limit):
# GH 9217: make sure limit is greater than zero.
s = Series([1, 2, np.nan, 4])
method, kwargs = nontemporal_method
with pytest.raises(ValueError, match="Limit must be greater than 0"):
s.interpolate(limit=limit, method=method, **kwargs)
Reported by Pylint.
Line: 328
Column: 52
with pytest.raises(ValueError, match="Limit must be greater than 0"):
s.interpolate(limit=limit, method=method, **kwargs)
def test_interpolate_invalid_float_limit(self, nontemporal_method):
# GH 9217: make sure limit is an integer.
s = Series([1, 2, np.nan, 4])
method, kwargs = nontemporal_method
limit = 2.0
with pytest.raises(ValueError, match="Limit must be an integer"):
Reported by Pylint.
Line: 759
Column: 47
pd.interval_range(start=0, end=4),
],
)
def test_interp_non_timedelta_index(self, interp_methods_ind, ind):
# gh 21662
df = pd.DataFrame([0, 1, np.nan, 3], index=ind)
method, kwargs = interp_methods_ind
if method == "pchip":
Reported by Pylint.
Line: 781
Column: 48
with pytest.raises(ValueError, match=expected_error):
df[0].interpolate(method=method, **kwargs)
def test_interpolate_timedelta_index(self, interp_methods_ind):
"""
Tests for non numerical index types - object, period, timedelta
Note that all methods except time, index, nearest and values
are tested here.
"""
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Index,
MultiIndex,
Reported by Pylint.
Line: 80
Column: 1
return method, kwargs
class TestSeriesInterpolateData:
def test_interpolate(self, datetime_series, string_series):
ts = Series(np.arange(len(datetime_series), dtype=float), datetime_series.index)
ts_copy = ts.copy()
ts_copy[5:10] = np.NaN
Reported by Pylint.
Line: 80
Column: 1
return method, kwargs
class TestSeriesInterpolateData:
def test_interpolate(self, datetime_series, string_series):
ts = Series(np.arange(len(datetime_series), dtype=float), datetime_series.index)
ts_copy = ts.copy()
ts_copy[5:10] = np.NaN
Reported by Pylint.
pandas/tests/io/test_pickle.py
153 issues
Line: 32
Column: 1
import zipfile
import numpy as np
import pytest
from pandas.compat import (
get_lzma_file,
import_lzma,
is_platform_little_endian,
Reported by Pylint.
Line: 57
Column: 3
lzma = import_lzma()
# TODO(ArrayManager) pickling
pytestmark = [
td.skip_array_manager_not_yet_implemented,
pytest.mark.filterwarnings("ignore:Timestamp.freq is deprecated:FutureWarning"),
]
Reported by Pylint.
Line: 80
Column: 44
# ---------------------
# comparison functions
# ---------------------
def compare_element(result, expected, typ, version=None):
if isinstance(expected, Index):
tm.assert_index_equal(expected, result)
return
if typ.startswith("sp_"):
Reported by Pylint.
Line: 117
Column: 41
return data
def compare_series_ts(result, expected, typ, version):
# GH 7748
tm.assert_series_equal(result, expected)
assert result.index.freq == expected.index.freq
assert not result.index.freq.normalize
tm.assert_series_equal(result > 0, expected > 0)
Reported by Pylint.
Line: 117
Column: 46
return data
def compare_series_ts(result, expected, typ, version):
# GH 7748
tm.assert_series_equal(result, expected)
assert result.index.freq == expected.index.freq
assert not result.index.freq.normalize
tm.assert_series_equal(result > 0, expected > 0)
Reported by Pylint.
Line: 137
Column: 44
assert res == pd.Timedelta(days=1, nanoseconds=1)
def compare_series_dt_tz(result, expected, typ, version):
tm.assert_series_equal(result, expected)
def compare_series_cat(result, expected, typ, version):
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 137
Column: 49
assert res == pd.Timedelta(days=1, nanoseconds=1)
def compare_series_dt_tz(result, expected, typ, version):
tm.assert_series_equal(result, expected)
def compare_series_cat(result, expected, typ, version):
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 141
Column: 42
tm.assert_series_equal(result, expected)
def compare_series_cat(result, expected, typ, version):
tm.assert_series_equal(result, expected)
def compare_frame_dt_mixed_tzs(result, expected, typ, version):
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 141
Column: 47
tm.assert_series_equal(result, expected)
def compare_series_cat(result, expected, typ, version):
tm.assert_series_equal(result, expected)
def compare_frame_dt_mixed_tzs(result, expected, typ, version):
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 145
Column: 50
tm.assert_series_equal(result, expected)
def compare_frame_dt_mixed_tzs(result, expected, typ, version):
tm.assert_frame_equal(result, expected)
def compare_frame_cat_onecol(result, expected, typ, version):
tm.assert_frame_equal(result, expected)
Reported by Pylint.
pandas/tests/frame/methods/test_sort_index.py
153 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalDtype,
CategoricalIndex,
DataFrame,
Index,
Reported by Pylint.
Line: 27
Column: 16
levels=[["a", "b"], ["bb", "aa"]], codes=[[0, 0, 1, 1], [0, 1, 0, 1]]
),
)
assert df.index._is_lexsorted()
assert not df.index.is_monotonic
# sort it
expected = DataFrame(
{"value": [2, 1, 4, 3]},
Reported by Pylint.
Line: 44
Column: 24
# reconstruct
result = df.sort_index().copy()
result.index = result.index._sort_levels_monotonic()
assert result.index.is_monotonic
tm.assert_frame_equal(result, expected)
def test_sort_index_non_existent_label_multiindex(self):
Reported by Pylint.
Line: 525
Column: 16
[(0.5, "a"), (0.5, "b"), (0.8, "a"), (0.8, "b")]
),
)
assert expected.index._is_lexsorted()
result = DataFrame(
[[1, 1], [2, 2], [1, 1], [2, 2]],
index=MultiIndex.from_product([[0.5, 0.8], list("ab")]),
)
Reported by Pylint.
Line: 543
Column: 16
),
)
result = result.sort_index()
assert result.index._is_lexsorted()
tm.assert_frame_equal(result, expected)
concatted = pd.concat([df, df], keys=[0.8, 0.5])
result = concatted.sort_index()
Reported by Pylint.
Line: 572
Column: 3
result = df.sort_index(axis=1, level=1)
assert result.columns.is_monotonic
# TODO: better name, de-duplicate with test_sort_index_level above
def test_sort_index_level2(self):
mi = MultiIndex(
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=["first", "second"],
Reported by Pylint.
Line: 610
Column: 16
# it works!
result = df.sort_index(level=0)
assert result.index._lexsort_depth == 3
# GH#2684 (int32)
index = MultiIndex.from_arrays([np.arange(4000)] * 3)
df = DataFrame(np.random.randn(4000).astype("int32"), index=index)
Reported by Pylint.
Line: 619
Column: 16
# it works!
result = df.sort_index(level=0)
assert (result.dtypes.values == df.dtypes.values).all()
assert result.index._lexsort_depth == 3
def test_sort_index_level_by_name(self):
mi = MultiIndex(
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalDtype,
CategoricalIndex,
DataFrame,
Index,
Reported by Pylint.
Line: 18
Column: 1
import pandas._testing as tm
class TestDataFrameSortIndex:
def test_sort_index_and_reconstruction_doc_example(self):
# doc example
df = DataFrame(
{"value": [1, 2, 3, 4]},
index=MultiIndex(
Reported by Pylint.
pandas/core/reshape/merge.py
151 issues
Line: 20
Column: 1
import numpy as np
from pandas._libs import (
Timedelta,
hashtable as libhashtable,
join as libjoin,
lib,
)
Reported by Pylint.
Line: 20
Column: 1
import numpy as np
from pandas._libs import (
Timedelta,
hashtable as libhashtable,
join as libjoin,
lib,
)
Reported by Pylint.
Line: 20
Column: 1
import numpy as np
from pandas._libs import (
Timedelta,
hashtable as libhashtable,
join as libjoin,
lib,
)
Reported by Pylint.
Line: 1007
Column: 18
self,
index: Index,
other_index: Index,
indexer: npt.NDArray[np.intp],
how: str = "left",
) -> Index:
"""
Create a join index by rearranging one index to match another
Reported by Pylint.
Line: 1452
Column: 12
def get_join_indexers(
left_keys, right_keys, sort: bool = False, how: str = "inner", **kwargs
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
"""
Parameters
----------
left_keys : ndarray, Index, Series
Reported by Pylint.
Line: 1452
Column: 34
def get_join_indexers(
left_keys, right_keys, sort: bool = False, how: str = "inner", **kwargs
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
"""
Parameters
----------
left_keys : ndarray, Index, Series
Reported by Pylint.
Line: 1511
Column: 15
right: MultiIndex,
dropped_level_names,
join_index: Index,
lindexer: npt.NDArray[np.intp],
rindexer: npt.NDArray[np.intp],
) -> tuple[list[Index], npt.NDArray[np.intp], list[Hashable]]:
"""
*this is an internal non-public method*
Reported by Pylint.
Line: 1512
Column: 15
dropped_level_names,
join_index: Index,
lindexer: npt.NDArray[np.intp],
rindexer: npt.NDArray[np.intp],
) -> tuple[list[Index], npt.NDArray[np.intp], list[Hashable]]:
"""
*this is an internal non-public method*
Returns the levels, labels and names of a multi-index to multi-index join.
Reported by Pylint.
Line: 1513
Column: 25
join_index: Index,
lindexer: npt.NDArray[np.intp],
rindexer: npt.NDArray[np.intp],
) -> tuple[list[Index], npt.NDArray[np.intp], list[Hashable]]:
"""
*this is an internal non-public method*
Returns the levels, labels and names of a multi-index to multi-index join.
Depending on the type of join, this method restores the appropriate
Reported by Pylint.
Line: 2069
Column: 34
def _factorize_keys(
lk: ArrayLike, rk: ArrayLike, sort: bool = True, how: str = "inner"
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]:
"""
Encode left and right keys as enumerated types.
This is used to get the join indexers to be used when merging DataFrames.
Reported by Pylint.