The following issues were found
pandas/tests/reshape/test_cut.py
73 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
Categorical,
DataFrame,
DatetimeIndex,
Index,
Reported by Pylint.
Line: 234
Column: 13
def test_labels(right, breaks, closed):
arr = np.tile(np.arange(0, 1.01, 0.1), 4)
result, bins = cut(arr, 4, retbins=True, right=right)
ex_levels = IntervalIndex.from_breaks(breaks, closed=closed)
tm.assert_index_equal(result.categories, ex_levels)
def test_cut_pass_series_name_to_factor():
Reported by Pylint.
Line: 346
Column: 14
)
def test_round_frac(val, precision, expected):
# see gh-1979
result = tmod._round_frac(val, precision=precision)
assert result == expected
def test_cut_return_intervals():
ser = Series([0, 1, 2, 3, 4, 5, 6, 7, 8])
Reported by Pylint.
Line: 368
Column: 13
def test_series_ret_bins():
# see gh-8589
ser = Series(np.arange(4))
result, bins = cut(ser, 2, retbins=True)
expected = Series(
IntervalIndex.from_breaks([-0.003, 1.5, 3], closed="right").repeat(2)
).astype(CDT(ordered=True))
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 430
Column: 9
@pytest.mark.parametrize(
"conv",
[
lambda v: Timestamp(v),
lambda v: to_datetime(v),
lambda v: np.datetime64(v),
lambda v: Timestamp(v).to_pydatetime(),
],
)
Reported by Pylint.
Line: 431
Column: 9
"conv",
[
lambda v: Timestamp(v),
lambda v: to_datetime(v),
lambda v: np.datetime64(v),
lambda v: Timestamp(v).to_pydatetime(),
],
)
def test_datetime_bin(conv):
Reported by Pylint.
Line: 432
Column: 9
[
lambda v: Timestamp(v),
lambda v: to_datetime(v),
lambda v: np.datetime64(v),
lambda v: Timestamp(v).to_pydatetime(),
],
)
def test_datetime_bin(conv):
data = [np.datetime64("2012-12-13"), np.datetime64("2012-12-15")]
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
Categorical,
DataFrame,
DatetimeIndex,
Index,
Reported by Pylint.
Line: 27
Column: 1
import pandas.core.reshape.tile as tmod
def test_simple():
data = np.ones(5, dtype="int64")
result = cut(data, 4, labels=False)
expected = np.array([1, 1, 1, 1, 1])
tm.assert_numpy_array_equal(result, expected, check_dtype=False)
Reported by Pylint.
Line: 36
Column: 1
@pytest.mark.parametrize("func", [list, np.array])
def test_bins(func):
data = func([0.2, 1.4, 2.5, 6.2, 9.7, 2.1])
result, bins = cut(data, 3, retbins=True)
intervals = IntervalIndex.from_breaks(bins.round(3))
intervals = intervals.take([0, 0, 0, 1, 2, 0])
Reported by Pylint.
pandas/tests/util/test_hashing.py
73 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Index,
MultiIndex,
Series,
Reported by Pylint.
Line: 87
Column: 21
tm.assert_series_equal(result, expected)
def test_hash_array(series):
arr = series.values
tm.assert_numpy_array_equal(hash_array(arr), hash_array(arr))
@pytest.mark.parametrize(
Reported by Pylint.
Line: 143
Column: 14
codes=[[0, 1, 0, 2], [2, 0, 0, 1]],
names=["col1", "col2"],
)
recons = mi._sort_levels_monotonic()
# These are equal.
assert mi.equals(recons)
assert Index(mi.values).equals(Index(recons.values))
Reported by Pylint.
Line: 180
Column: 34
MultiIndex.from_product([pd.CategoricalIndex(list("aabc")), range(3)]),
],
)
def test_hash_pandas_object(obj, index):
_check_equal(obj, index=index)
_check_not_equal_with_index(obj)
def test_hash_pandas_object2(series, index):
Reported by Pylint.
Line: 185
Column: 38
_check_not_equal_with_index(obj)
def test_hash_pandas_object2(series, index):
_check_equal(series, index=index)
_check_not_equal_with_index(series)
@pytest.mark.parametrize(
Reported by Pylint.
Line: 185
Column: 30
_check_not_equal_with_index(obj)
def test_hash_pandas_object2(series, index):
_check_equal(series, index=index)
_check_not_equal_with_index(series)
@pytest.mark.parametrize(
Reported by Pylint.
Line: 193
Column: 40
@pytest.mark.parametrize(
"obj", [Series([], dtype="float64"), Series([], dtype="object"), Index([])]
)
def test_hash_pandas_empty_object(obj, index):
# These are by-definition the same with
# or without the index as the data is empty.
_check_equal(obj, index=index)
Reported by Pylint.
Line: 292
Column: 26
hash_pandas_object(Series(list("abc")), hash_key="foo")
def test_already_encoded(index):
# If already encoded, then ok.
obj = Series(list("abc")).str.encode("utf8")
_check_equal(obj, index=index)
Reported by Pylint.
Line: 298
Column: 29
_check_equal(obj, index=index)
def test_alternate_encoding(index):
obj = Series(list("abc"))
_check_equal(obj, index=index, encoding="ascii")
@pytest.mark.parametrize("l_exp", range(8))
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Index,
MultiIndex,
Series,
Reported by Pylint.
pandas/core/indexes/datetimelike.py
73 issues
Line: 20
Column: 1
import numpy as np
from pandas._libs import (
NaT,
Timedelta,
lib,
)
from pandas._libs.tslibs import (
Reported by Pylint.
Line: 25
Column: 1
Timedelta,
lib,
)
from pandas._libs.tslibs import (
BaseOffset,
NaTType,
Resolution,
Tick,
parsing,
Reported by Pylint.
Line: 683
Column: 22
# With sort being False, we can't infer that result.freq == self.freq
# TODO: no tests rely on the _with_freq("infer"); needed?
result = type(self)._simple_new(dates, name=self.name)
result = result._with_freq("infer")
return result
else:
left, right = other, self
left_end = left[-1]
Reported by Pylint.
Line: 683
Column: 22
# With sort being False, we can't infer that result.freq == self.freq
# TODO: no tests rely on the _with_freq("infer"); needed?
result = type(self)._simple_new(dates, name=self.name)
result = result._with_freq("infer")
return result
else:
left, right = other, self
left_end = left[-1]
Reported by Pylint.
Line: 70
Column: 26
if TYPE_CHECKING:
from pandas import CategoricalIndex
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
_T = TypeVar("_T", bound="DatetimeIndexOpsMixin")
@inherit_names(
Reported by Pylint.
Line: 97
Column: 9
# error: "Callable[[Any], Any]" has no attribute "fget"
hasnans = cache_readonly(
DatetimeLikeArrayMixin._hasnans.fget # type: ignore[attr-defined]
)
@property
def _is_all_dates(self) -> bool:
return True
Reported by Pylint.
Line: 101
Column: 5
)
@property
def _is_all_dates(self) -> bool:
return True
# ------------------------------------------------------------------------
# Abstract data attributes
Reported by Pylint.
Line: 110
Column: 16
@property
def values(self) -> np.ndarray:
# Note: PeriodArray overrides this to return an ndarray of objects.
return self._data._ndarray
def __array_wrap__(self, result, context=None):
"""
Gets called after a ufunc and other functions.
"""
Reported by Pylint.
Line: 118
Column: 19
"""
out = super().__array_wrap__(result, context=context)
if isinstance(out, DatetimeTimedeltaMixin) and self.freq is not None:
out = out._with_freq("infer")
return out
# ------------------------------------------------------------------------
def equals(self, other: Any) -> bool:
Reported by Pylint.
Line: 136
Column: 25
return False
elif not isinstance(other, type(self)):
should_try = False
inferable = self._data._infer_matches
if other.dtype == object:
should_try = other.inferred_type in inferable
elif is_categorical_dtype(other.dtype):
other = cast("CategoricalIndex", other)
should_try = other.categories.inferred_type in inferable
Reported by Pylint.
pandas/tests/frame/methods/test_interpolate.py
73 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
DataFrame,
Series,
date_range,
Reported by Pylint.
Line: 210
Column: 3
}
)
df.interpolate(axis=0)
# TODO: assert something?
@pytest.mark.parametrize(
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
)
def test_interp_leading_nans(self, check_scipy):
Reported by Pylint.
Line: 306
Column: 45
result = df[["B", "D"]].interpolate(downcast=None)
tm.assert_frame_equal(result, df[["B", "D"]])
def test_interp_time_inplace_axis(self, axis):
# GH 9687
periods = 5
idx = date_range(start="2014-01-01", periods=periods)
data = np.random.rand(periods, periods)
data[data < 0.5] = np.nan
Reported by Pylint.
Line: 331
Column: 3
expected = df.interpolate(method="linear", axis=axis_number)
tm.assert_frame_equal(result, expected)
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) support axis=1
@pytest.mark.parametrize("method", ["ffill", "bfill", "pad"])
def test_interp_fillna_methods(self, axis, method):
# GH 12918
df = DataFrame(
{
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
DataFrame,
Series,
date_range,
Reported by Pylint.
Line: 14
Column: 1
import pandas._testing as tm
class TestDataFrameInterpolate:
def test_interp_basic(self):
df = DataFrame(
{
"A": [1, 2, np.nan, 4],
"B": [1, 4, 9, np.nan],
Reported by Pylint.
Line: 15
Column: 5
class TestDataFrameInterpolate:
def test_interp_basic(self):
df = DataFrame(
{
"A": [1, 2, np.nan, 4],
"B": [1, 4, 9, np.nan],
"C": [1, 2, 3, 5],
Reported by Pylint.
Line: 15
Column: 5
class TestDataFrameInterpolate:
def test_interp_basic(self):
df = DataFrame(
{
"A": [1, 2, np.nan, 4],
"B": [1, 4, 9, np.nan],
"C": [1, 2, 3, 5],
Reported by Pylint.
Line: 16
Column: 9
class TestDataFrameInterpolate:
def test_interp_basic(self):
df = DataFrame(
{
"A": [1, 2, np.nan, 4],
"B": [1, 4, 9, np.nan],
"C": [1, 2, 3, 5],
"D": list("abcd"),
Reported by Pylint.
Line: 41
Column: 5
expected.loc[5, "B"] = 9
tm.assert_frame_equal(result, expected)
def test_interp_empty(self):
# https://github.com/pandas-dev/pandas/issues/35598
df = DataFrame()
result = df.interpolate()
assert result is not df
expected = df
Reported by Pylint.
pandas/tests/io/test_clipboard.py
73 issues
Line: 4
Column: 1
from textwrap import dedent
import numpy as np
import pytest
from pandas import (
DataFrame,
get_option,
read_clipboard,
Reported by Pylint.
Line: 142
Column: 25
@pytest.mark.clipboard
def test_mock_clipboard(mock_clipboard):
import pandas.io.clipboard
pandas.io.clipboard.clipboard_set("abc")
assert "abc" in set(mock_clipboard.values())
result = pandas.io.clipboard.clipboard_get()
Reported by Pylint.
Line: 161
Column: 37
tm.assert_frame_equal(data, result)
# Test that default arguments copy as tab delimited
def test_round_trip_frame(self, df):
self.check_round_trip_frame(df)
# Test that explicit delimiters are respected
@pytest.mark.parametrize("sep", ["\t", ",", "|"])
def test_round_trip_frame_sep(self, df, sep):
Reported by Pylint.
Line: 166
Column: 41
# Test that explicit delimiters are respected
@pytest.mark.parametrize("sep", ["\t", ",", "|"])
def test_round_trip_frame_sep(self, df, sep):
self.check_round_trip_frame(df, sep=sep)
# Test white space separator
def test_round_trip_frame_string(self, df):
df.to_clipboard(excel=False, sep=None)
Reported by Pylint.
Line: 170
Column: 44
self.check_round_trip_frame(df, sep=sep)
# Test white space separator
def test_round_trip_frame_string(self, df):
df.to_clipboard(excel=False, sep=None)
result = read_clipboard()
assert df.to_string() == result.to_string()
assert df.shape == result.shape
Reported by Pylint.
Line: 178
Column: 38
# Two character separator is not supported in to_clipboard
# Test that multi-character separators are not silently passed
def test_excel_sep_warning(self, df):
with tm.assert_produces_warning():
df.to_clipboard(excel=True, sep=r"\t")
# Separator is ignored when excel=False and should produce a warning
def test_copy_delim_warning(self, df):
Reported by Pylint.
Line: 183
Column: 39
df.to_clipboard(excel=True, sep=r"\t")
# Separator is ignored when excel=False and should produce a warning
def test_copy_delim_warning(self, df):
with tm.assert_produces_warning():
df.to_clipboard(excel=False, sep="\t")
# Tests that the default behavior of to_clipboard is tab
# delimited and excel="True"
Reported by Pylint.
Line: 191
Column: 60
# delimited and excel="True"
@pytest.mark.parametrize("sep", ["\t", None, "default"])
@pytest.mark.parametrize("excel", [True, None, "default"])
def test_clipboard_copy_tabs_default(self, sep, excel, df, request, mock_clipboard):
kwargs = build_kwargs(sep, excel)
df.to_clipboard(**kwargs)
assert mock_clipboard[request.node.name] == df.to_csv(sep="\t")
# Tests reading of white space separated tables
Reported by Pylint.
Line: 191
Column: 73
# delimited and excel="True"
@pytest.mark.parametrize("sep", ["\t", None, "default"])
@pytest.mark.parametrize("excel", [True, None, "default"])
def test_clipboard_copy_tabs_default(self, sep, excel, df, request, mock_clipboard):
kwargs = build_kwargs(sep, excel)
df.to_clipboard(**kwargs)
assert mock_clipboard[request.node.name] == df.to_csv(sep="\t")
# Tests reading of white space separated tables
Reported by Pylint.
Line: 199
Column: 55
# Tests reading of white space separated tables
@pytest.mark.parametrize("sep", [None, "default"])
@pytest.mark.parametrize("excel", [False])
def test_clipboard_copy_strings(self, sep, excel, df):
kwargs = build_kwargs(sep, excel)
df.to_clipboard(**kwargs)
result = read_clipboard(sep=r"\s+")
assert result.to_string() == df.to_string()
assert df.shape == result.shape
Reported by Pylint.
pandas/tests/indexes/multi/test_setops.py
73 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalIndex,
Index,
IntervalIndex,
MultiIndex,
Reported by Pylint.
Line: 206
Column: 3
@pytest.mark.xfail(reason="Not implemented.")
def test_difference_sort_special_true():
# TODO decide on True behaviour
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
result = idx.difference([], sort=True)
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 256
Column: 3
the_union = idx.union(idx[:0], sort=sort)
tm.assert_index_equal(the_union, idx)
# FIXME: dont leave commented-out
# won't work in python 3
# tuples = _index.values
# result = _index[:4] | tuples[4:]
# assert result.equals(tuples)
Reported by Pylint.
Line: 293
Column: 3
expected = idx[:0]
assert empty.equals(expected)
# FIXME: dont leave commented-out
# can't do in python 3
# tuples = _index.values
# result = _index & tuples
# assert result.equals(tuples)
Reported by Pylint.
Line: 343
Column: 3
@pytest.mark.xfail(reason="Not implemented.")
def test_intersect_equal_sort_true():
# TODO decide on True behaviour
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
sorted_ = MultiIndex.from_product([[0, 1], ["a", "b"]])
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
Reported by Pylint.
Line: 365
Column: 38
@pytest.mark.xfail(reason="Not implemented.")
def test_union_sort_other_empty_sort(slice_):
# TODO decide on True behaviour
# # sort=True
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
other = idx[:0]
result = idx.union(other, sort=True)
Reported by Pylint.
Line: 366
Column: 3
@pytest.mark.xfail(reason="Not implemented.")
def test_union_sort_other_empty_sort(slice_):
# TODO decide on True behaviour
# # sort=True
idx = MultiIndex.from_product([[1, 0], ["a", "b"]])
other = idx[:0]
result = idx.union(other, sort=True)
expected = MultiIndex.from_product([[0, 1], ["a", "b"]])
Reported by Pylint.
Line: 391
Column: 3
@pytest.mark.xfail(reason="Not implemented.")
def test_union_sort_other_incomparable_sort():
# TODO decide on True behaviour
# # sort=True
idx = MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])
with pytest.raises(TypeError, match="Cannot compare"):
idx.union(idx[:1], sort=True)
Reported by Pylint.
Line: 483
Column: 14
# GH#38323
mi = MultiIndex.from_tuples([], names=["a", "b"])
mi2 = MultiIndex.from_tuples([data], names=names)
result = mi._maybe_match_names(mi2)
assert result == expected
def test_intersection_equal_different_names():
# GH#30302
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
CategoricalIndex,
Index,
IntervalIndex,
MultiIndex,
Reported by Pylint.
pandas/tests/test_sorting.py
72 issues
Line: 6
Column: 1
from itertools import product
import numpy as np
import pytest
from pandas import (
DataFrame,
MultiIndex,
Series,
Reported by Pylint.
Line: 1
Column: 1
from collections import defaultdict
from datetime import datetime
from itertools import product
import numpy as np
import pytest
from pandas import (
DataFrame,
Reported by Pylint.
Line: 28
Column: 1
)
class TestSorting:
@pytest.mark.slow
def test_int64_overflow(self):
B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
A = np.arange(2500)
Reported by Pylint.
Line: 30
Column: 5
class TestSorting:
@pytest.mark.slow
def test_int64_overflow(self):
B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
A = np.arange(2500)
df = DataFrame(
{
Reported by Pylint.
Line: 30
Column: 5
class TestSorting:
@pytest.mark.slow
def test_int64_overflow(self):
B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
A = np.arange(2500)
df = DataFrame(
{
Reported by Pylint.
Line: 32
Column: 9
@pytest.mark.slow
def test_int64_overflow(self):
B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
A = np.arange(2500)
df = DataFrame(
{
"A": A,
"B": B,
Reported by Pylint.
Line: 33
Column: 9
def test_int64_overflow(self):
B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
A = np.arange(2500)
df = DataFrame(
{
"A": A,
"B": B,
"C": A,
Reported by Pylint.
Line: 34
Column: 9
B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
A = np.arange(2500)
df = DataFrame(
{
"A": A,
"B": B,
"C": A,
"D": B,
Reported by Pylint.
Line: 48
Column: 9
}
)
lg = df.groupby(["A", "B", "C", "D", "E", "F", "G", "H"])
rg = df.groupby(["H", "G", "F", "E", "D", "C", "B", "A"])
left = lg.sum()["values"]
right = rg.sum()["values"]
Reported by Pylint.
Line: 49
Column: 9
)
lg = df.groupby(["A", "B", "C", "D", "E", "F", "G", "H"])
rg = df.groupby(["H", "G", "F", "E", "D", "C", "B", "A"])
left = lg.sum()["values"]
right = rg.sum()["values"]
exp_index, _ = left.index.sortlevel()
Reported by Pylint.
asv_bench/benchmarks/sparse.py
72 issues
Line: 2
Column: 1
import numpy as np
import scipy.sparse
import pandas as pd
from pandas import (
MultiIndex,
Series,
date_range,
)
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import scipy.sparse
import pandas as pd
from pandas import (
MultiIndex,
Series,
date_range,
)
Reported by Pylint.
Line: 5
Column: 1
import scipy.sparse
import pandas as pd
from pandas import (
MultiIndex,
Series,
date_range,
)
from pandas.arrays import SparseArray
Reported by Pylint.
Line: 10
Column: 1
Series,
date_range,
)
from pandas.arrays import SparseArray
def make_array(size, dense_proportion, fill_value, dtype):
dense_size = int(size * dense_proportion)
arr = np.full(size, fill_value, dtype)
Reported by Pylint.
Line: 143
Column: 1
self.arr1 / self.arr2
from .pandas_vb_common import setup # noqa: F401 isort:skip
Reported by Pylint.
Line: 26
Column: 9
K = 50
N = 50001
rng = date_range("1/1/2000", periods=N, freq="T")
self.series = {}
for i in range(1, K):
data = np.random.randn(N)[:-i]
idx = rng[:-i]
data[100:] = np.nan
self.series[i] = Series(SparseArray(data), index=idx)
Reported by Pylint.
Line: 44
Column: 9
def setup(self, dense_proportion, fill_value, dtype):
N = 10 ** 6
self.array = make_array(N, dense_proportion, fill_value, dtype)
def time_sparse_array(self, dense_proportion, fill_value, dtype):
SparseArray(self.array, fill_value=fill_value, dtype=dtype)
Reported by Pylint.
Line: 46
Column: 33
N = 10 ** 6
self.array = make_array(N, dense_proportion, fill_value, dtype)
def time_sparse_array(self, dense_proportion, fill_value, dtype):
SparseArray(self.array, fill_value=fill_value, dtype=dtype)
class SparseDataFrameConstructor:
def setup(self):
Reported by Pylint.
Line: 53
Column: 9
class SparseDataFrameConstructor:
def setup(self):
N = 1000
self.sparse = scipy.sparse.rand(N, N, 0.005)
def time_from_scipy(self):
pd.DataFrame.sparse.from_spmatrix(self.sparse)
Reported by Pylint.
Line: 61
Column: 9
class FromCoo:
def setup(self):
self.matrix = scipy.sparse.coo_matrix(
([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])), shape=(100, 100)
)
def time_sparse_series_from_coo(self):
Series.sparse.from_coo(self.matrix)
Reported by Pylint.
pandas/tests/io/sas/test_sas7bdat.py
72 issues
Line: 8
Column: 1
import dateutil.parser
import numpy as np
import pytest
from pandas.errors import (
EmptyDataError,
PerformanceWarning,
)
Reported by Pylint.
Line: 90
Column: 9
@td.skip_if_no("py.path")
@pytest.mark.slow
def test_path_localpath(self):
from py.path import local as LocalPath
for j in 0, 1:
df0 = self.data[j]
for k in self.test_ix[j]:
fname = LocalPath(os.path.join(self.dirpath, f"test{k}.sas7bdat"))
Reported by Pylint.
Line: 266
Column: 12
# GH 19732: Timestamps imported from sas will incur floating point errors
try:
df["dt_as_dt"] = df["dt_as_dt"].dt.round("us")
except pd._libs.tslibs.np_datetime.OutOfBoundsDatetime:
df = df.applymap(round_datetime_to_ms)
except AttributeError:
df["dt_as_dt"] = df["dt_as_dt"].apply(round_datetime_to_ms)
# if there are any date/times > pandas.Timestamp.max then ALL in that chunk
# are returned as datetime.datetime
Reported by Pylint.
Line: 302
Column: 16
# GH 19732: Timestamps imported from sas will incur floating point errors
try:
df["dt_as_dt"] = df["dt_as_dt"].dt.round("us")
except pd._libs.tslibs.np_datetime.OutOfBoundsDatetime:
df = df.applymap(round_datetime_to_ms)
except AttributeError:
df["dt_as_dt"] = df["dt_as_dt"].apply(round_datetime_to_ms)
df.reset_index(inplace=True, drop=True)
results.append(df)
Reported by Pylint.
Line: 25
Column: 9
class TestSAS7BDAT:
@pytest.fixture(autouse=True)
def setup_method(self, datapath):
self.dirpath = datapath("io", "sas", "data")
self.data = []
self.test_ix = [list(range(1, 16)), [16]]
for j in 1, 2:
fname = os.path.join(self.dirpath, f"test_sas7bdat_{j}.csv")
df = pd.read_csv(fname)
Reported by Pylint.
Line: 26
Column: 9
@pytest.fixture(autouse=True)
def setup_method(self, datapath):
self.dirpath = datapath("io", "sas", "data")
self.data = []
self.test_ix = [list(range(1, 16)), [16]]
for j in 1, 2:
fname = os.path.join(self.dirpath, f"test_sas7bdat_{j}.csv")
df = pd.read_csv(fname)
epoch = datetime(1960, 1, 1)
Reported by Pylint.
Line: 27
Column: 9
def setup_method(self, datapath):
self.dirpath = datapath("io", "sas", "data")
self.data = []
self.test_ix = [list(range(1, 16)), [16]]
for j in 1, 2:
fname = os.path.join(self.dirpath, f"test_sas7bdat_{j}.csv")
df = pd.read_csv(fname)
epoch = datetime(1960, 1, 1)
t1 = pd.to_timedelta(df["Column4"], unit="d")
Reported by Pylint.
Line: 266
Column: 12
# GH 19732: Timestamps imported from sas will incur floating point errors
try:
df["dt_as_dt"] = df["dt_as_dt"].dt.round("us")
except pd._libs.tslibs.np_datetime.OutOfBoundsDatetime:
df = df.applymap(round_datetime_to_ms)
except AttributeError:
df["dt_as_dt"] = df["dt_as_dt"].apply(round_datetime_to_ms)
# if there are any date/times > pandas.Timestamp.max then ALL in that chunk
# are returned as datetime.datetime
Reported by Pylint.
Line: 302
Column: 16
# GH 19732: Timestamps imported from sas will incur floating point errors
try:
df["dt_as_dt"] = df["dt_as_dt"].dt.round("us")
except pd._libs.tslibs.np_datetime.OutOfBoundsDatetime:
df = df.applymap(round_datetime_to_ms)
except AttributeError:
df["dt_as_dt"] = df["dt_as_dt"].apply(round_datetime_to_ms)
df.reset_index(inplace=True, drop=True)
results.append(df)
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import io
import os
from pathlib import Path
import dateutil.parser
import numpy as np
import pytest
Reported by Pylint.
pandas/tests/indexes/multi/test_sorting.py
72 issues
Line: 4
Column: 1
import random
import numpy as np
import pytest
from pandas.errors import (
PerformanceWarning,
UnsortedIndexError,
)
Reported by Pylint.
Line: 238
Column: 11
# because tests should be deterministic (and this test in particular
# checks that levels are removed, which is not the case for every
# random input):
rng = np.random.RandomState(4) # seed is arbitrary value that works
size = 1 << 16
df = DataFrame(
{
"first": rng.randint(0, 1 << 13, size).astype(first_type),
Reported by Pylint.
Line: 122
Column: 9
r"slicing on levels \[1\], lexsort depth 0"
)
with pytest.raises(UnsortedIndexError, match=msg):
df.loc(axis=0)["z", slice("a")]
df.sort_index(inplace=True)
assert len(df.loc(axis=0)["z", :]) == 2
with pytest.raises(KeyError, match="'q'"):
df.loc(axis=0)["q", :]
Reported by Pylint.
Line: 127
Column: 9
assert len(df.loc(axis=0)["z", :]) == 2
with pytest.raises(KeyError, match="'q'"):
df.loc(axis=0)["q", :]
def test_unsortedindex_doc_examples():
# https://pandas.pydata.org/pandas-docs/stable/advanced.html#sorting-a-multiindex
dfm = DataFrame(
Reported by Pylint.
Line: 138
Column: 9
dfm = dfm.set_index(["jim", "joe"])
with tm.assert_produces_warning(PerformanceWarning):
dfm.loc[(1, "z")]
msg = r"Key length \(2\) was greater than MultiIndex lexsort depth \(1\)"
with pytest.raises(UnsortedIndexError, match=msg):
dfm.loc[(0, "y"):(1, "z")]
Reported by Pylint.
Line: 142
Column: 9
msg = r"Key length \(2\) was greater than MultiIndex lexsort depth \(1\)"
with pytest.raises(UnsortedIndexError, match=msg):
dfm.loc[(0, "y"):(1, "z")]
assert not dfm.index._is_lexsorted()
assert dfm.index._lexsort_depth == 1
# sort it
Reported by Pylint.
Line: 144
Column: 16
with pytest.raises(UnsortedIndexError, match=msg):
dfm.loc[(0, "y"):(1, "z")]
assert not dfm.index._is_lexsorted()
assert dfm.index._lexsort_depth == 1
# sort it
dfm = dfm.sort_index()
dfm.loc[(1, "z")]
Reported by Pylint.
Line: 145
Column: 12
dfm.loc[(0, "y"):(1, "z")]
assert not dfm.index._is_lexsorted()
assert dfm.index._lexsort_depth == 1
# sort it
dfm = dfm.sort_index()
dfm.loc[(1, "z")]
dfm.loc[(0, "y"):(1, "z")]
Reported by Pylint.
Line: 149
Column: 5
# sort it
dfm = dfm.sort_index()
dfm.loc[(1, "z")]
dfm.loc[(0, "y"):(1, "z")]
assert dfm.index._is_lexsorted()
assert dfm.index._lexsort_depth == 2
Reported by Pylint.
Line: 150
Column: 5
# sort it
dfm = dfm.sort_index()
dfm.loc[(1, "z")]
dfm.loc[(0, "y"):(1, "z")]
assert dfm.index._is_lexsorted()
assert dfm.index._lexsort_depth == 2
Reported by Pylint.