The following issues were found
pandas/tests/io/formats/test_format.py
1134 issues
Line: 18
Column: 1
import dateutil
import numpy as np
import pytest
import pytz
from pandas.compat import (
IS64,
is_platform_windows,
Reported by Pylint.
Line: 19
Column: 1
import dateutil
import numpy as np
import pytest
import pytz
from pandas.compat import (
IS64,
is_platform_windows,
)
Reported by Pylint.
Line: 59
Column: 24
@pytest.fixture
def filepath_or_buffer(filepath_or_buffer_id, tmp_path):
"""
A fixture yielding a string representing a filepath, a path-like object
and a StringIO buffer. Also checks that buffer is not closed.
"""
if filepath_or_buffer_id == "buffer":
Reported by Pylint.
Line: 78
Column: 5
@pytest.fixture
def assert_filepath_or_buffer_equals(
filepath_or_buffer, filepath_or_buffer_id, encoding
):
"""
Assertion helper for checking filepath_or_buffer.
"""
Reported by Pylint.
Line: 78
Column: 25
@pytest.fixture
def assert_filepath_or_buffer_equals(
filepath_or_buffer, filepath_or_buffer_id, encoding
):
"""
Assertion helper for checking filepath_or_buffer.
"""
Reported by Pylint.
Line: 131
Column: 13
return False
# Make sure each row has this ... in the same place
r = repr(df)
for ix, l in enumerate(r.splitlines()):
if not r.split()[cand_col] == "...":
return False
return True
Reported by Pylint.
Line: 131
Column: 9
return False
# Make sure each row has this ... in the same place
r = repr(df)
for ix, l in enumerate(r.splitlines()):
if not r.split()[cand_col] == "...":
return False
return True
Reported by Pylint.
Line: 242
Column: 3
assert "..." not in repr(df)
def test_repr_deprecation_negative_int(self):
# FIXME: remove in future version after deprecation cycle
# Non-regression test for:
# https://github.com/pandas-dev/pandas/issues/31532
width = get_option("display.max_colwidth")
with tm.assert_produces_warning(FutureWarning):
set_option("display.max_colwidth", -1)
Reported by Pylint.
Line: 313
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
# for the case of Index, where the repr is traditional rather than
# stylized
idx = Index(["a", "b"])
res = eval("pd." + repr(idx))
tm.assert_series_equal(Series(res), Series(idx))
def test_repr_should_return_str(self):
# https://docs.python.org/3/reference/datamodel.html#object.__repr__
# "...The return value must be a string object."
Reported by Bandit.
Line: 313
Column: 15
# for the case of Index, where the repr is traditional rather than
# stylized
idx = Index(["a", "b"])
res = eval("pd." + repr(idx))
tm.assert_series_equal(Series(res), Series(idx))
def test_repr_should_return_str(self):
# https://docs.python.org/3/reference/datamodel.html#object.__repr__
# "...The return value must be a string object."
Reported by Pylint.
pandas/tests/frame/test_constructors.py
842 issues
Line: 18
Column: 1
import numpy as np
import numpy.ma as ma
import numpy.ma.mrecords as mrecords
import pytest
import pytz
from pandas.compat import np_version_under1p19
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 19
Column: 1
import numpy.ma as ma
import numpy.ma.mrecords as mrecords
import pytest
import pytz
from pandas.compat import np_version_under1p19
import pandas.util._test_decorators as td
from pandas.core.dtypes.common import is_integer_dtype
Reported by Pylint.
Line: 1329
Column: 13
def __getitem__(self, n):
return self._lst.__getitem__(n)
def __len__(self, n):
return self._lst.__len__()
lst_containers = [DummyContainer([1, "a"]), DummyContainer([2, "b"])]
columns = ["num", "str"]
result = DataFrame(lst_containers, columns=columns)
Reported by Pylint.
Line: 2588
Column: 17
# after GH#7822
# these retain the timezones on dict construction
dr = date_range("2011/1/1", "2012/1/1", freq="W-FRI")
dr_tz = dr.tz_localize(tz)
df = DataFrame({"A": "foo", "B": dr_tz}, index=dr)
tz_expected = DatetimeTZDtype("ns", dr_tz.tzinfo)
assert df["B"].dtype == tz_expected
# GH#2810 (with timezones)
Reported by Pylint.
Line: 2588
Column: 17
# after GH#7822
# these retain the timezones on dict construction
dr = date_range("2011/1/1", "2012/1/1", freq="W-FRI")
dr_tz = dr.tz_localize(tz)
df = DataFrame({"A": "foo", "B": dr_tz}, index=dr)
tz_expected = DatetimeTZDtype("ns", dr_tz.tzinfo)
assert df["B"].dtype == tz_expected
# GH#2810 (with timezones)
Reported by Pylint.
Line: 131
Column: 16
arr = arr[:, 0]
obj = frame_or_series(arr, dtype=object)
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
# go through a different path in internals.construction
obj = frame_or_series(frame_or_series(arr), dtype=object)
assert obj._mgr.arrays[0].dtype == object
Reported by Pylint.
Line: 132
Column: 27
obj = frame_or_series(arr, dtype=object)
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
# go through a different path in internals.construction
obj = frame_or_series(frame_or_series(arr), dtype=object)
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
Reported by Pylint.
Line: 136
Column: 16
# go through a different path in internals.construction
obj = frame_or_series(frame_or_series(arr), dtype=object)
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
obj = frame_or_series(frame_or_series(arr), dtype=PandasDtype(object))
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
Reported by Pylint.
Line: 137
Column: 27
# go through a different path in internals.construction
obj = frame_or_series(frame_or_series(arr), dtype=object)
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
obj = frame_or_series(frame_or_series(arr), dtype=PandasDtype(object))
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
Reported by Pylint.
Line: 140
Column: 16
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
obj = frame_or_series(frame_or_series(arr), dtype=PandasDtype(object))
assert obj._mgr.arrays[0].dtype == object
assert isinstance(obj._mgr.arrays[0].ravel()[0], scalar_type)
if frame_or_series is DataFrame:
# other paths through internals.construction
sers = [Series(x) for x in arr]
Reported by Pylint.
pandas/tests/scalar/period/test_period.py
762 issues
Line: 8
Column: 1
)
import numpy as np
import pytest
import pytz
from pandas._libs.tslibs import (
iNaT,
period as libperiod,
Reported by Pylint.
Line: 9
Column: 1
import numpy as np
import pytest
import pytz
from pandas._libs.tslibs import (
iNaT,
period as libperiod,
)
Reported by Pylint.
Line: 11
Column: 1
import pytest
import pytz
from pandas._libs.tslibs import (
iNaT,
period as libperiod,
)
from pandas._libs.tslibs.ccalendar import (
DAYS,
Reported by Pylint.
Line: 15
Column: 1
iNaT,
period as libperiod,
)
from pandas._libs.tslibs.ccalendar import (
DAYS,
MONTHS,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
Reported by Pylint.
Line: 15
Column: 1
iNaT,
period as libperiod,
)
from pandas._libs.tslibs.ccalendar import (
DAYS,
MONTHS,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
Reported by Pylint.
Line: 19
Column: 1
DAYS,
MONTHS,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
from pandas._libs.tslibs.period import (
INVALID_FREQ_ERR_MSG,
IncompatibleFrequency,
)
Reported by Pylint.
Line: 19
Column: 1
DAYS,
MONTHS,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
from pandas._libs.tslibs.period import (
INVALID_FREQ_ERR_MSG,
IncompatibleFrequency,
)
Reported by Pylint.
Line: 20
Column: 1
MONTHS,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
from pandas._libs.tslibs.period import (
INVALID_FREQ_ERR_MSG,
IncompatibleFrequency,
)
from pandas._libs.tslibs.timezones import (
Reported by Pylint.
Line: 20
Column: 1
MONTHS,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
from pandas._libs.tslibs.period import (
INVALID_FREQ_ERR_MSG,
IncompatibleFrequency,
)
from pandas._libs.tslibs.timezones import (
Reported by Pylint.
Line: 21
Column: 1
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import DateParseError
from pandas._libs.tslibs.period import (
INVALID_FREQ_ERR_MSG,
IncompatibleFrequency,
)
from pandas._libs.tslibs.timezones import (
dateutil_gettz,
Reported by Pylint.
pandas/tests/plotting/test_datetimelike.py
679 issues
Line: 12
Column: 1
import sys
import numpy as np
import pytest
from pandas._libs.tslibs import (
BaseOffset,
to_offset,
)
Reported by Pylint.
Line: 87
Column: 19
def test_fontsize_set_correctly(self):
# For issue #8765
df = DataFrame(np.random.randn(10, 9), index=range(10))
fig, ax = self.plt.subplots()
df.plot(fontsize=2, ax=ax)
for label in ax.get_xticklabels() + ax.get_yticklabels():
assert label.get_fontsize() == 2
def test_frame_inferred(self):
Reported by Pylint.
Line: 122
Column: 19
idx = date_range("1/1/1987", freq="A", periods=3)
df = DataFrame({"A": ["x", "y", "z"], "B": [1, 2, 3]}, idx)
fig, ax = self.plt.subplots()
df.plot(ax=ax) # it works
assert len(ax.get_lines()) == 1 # B was plotted
self.plt.close(fig)
msg = "no numeric data to plot"
Reported by Pylint.
Line: 125
Column: 9
fig, ax = self.plt.subplots()
df.plot(ax=ax) # it works
assert len(ax.get_lines()) == 1 # B was plotted
self.plt.close(fig)
msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
df["A"].plot()
Reported by Pylint.
Line: 133
Column: 17
def test_tsplot(self):
_, ax = self.plt.subplots()
ts = tm.makeTimeSeries()
for s in self.period_ser:
_check_plot_works(s.plot, ax=ax)
Reported by Pylint.
Line: 142
Column: 17
for s in self.datetime_ser:
_check_plot_works(s.plot, ax=ax)
_, ax = self.plt.subplots()
ts.plot(style="k", ax=ax)
color = (0.0, 0.0, 0.0, 1)
assert color == ax.get_lines()[0].get_color()
def test_both_style_and_color(self):
Reported by Pylint.
Line: 165
Column: 21
def test_high_freq(self):
freaks = ["ms", "us"]
for freq in freaks:
_, ax = self.plt.subplots()
rng = date_range("1/1/2012", periods=100, freq=freq)
ser = Series(np.random.randn(len(rng)), rng)
_check_plot_works(ser.plot, ax=ax)
def test_get_datevalue(self):
Reported by Pylint.
Line: 191
Column: 17
)
annual = Series(1, index=date_range("2014-01-01", periods=3, freq="A-DEC"))
_, ax = self.plt.subplots()
annual.plot(ax=ax)
check_format_of_first_point(ax, "t = 2014 y = 1.000000")
# note this is added to the annual plot already in existence, and
# changes its freq field
Reported by Pylint.
Line: 250
Column: 17
_check_plot_works(ser.plot)
def test_fake_inferred_business(self):
_, ax = self.plt.subplots()
rng = date_range("2001-1-1", "2001-1-10")
ts = Series(range(len(rng)), index=rng)
ts = ts[:3].append(ts[5:])
ts.plot(ax=ax)
assert not hasattr(ax, "freq")
Reported by Pylint.
Line: 276
Column: 17
idx = date_range("2012-6-22 21:59:51.960928", freq="L", periods=500)
df = DataFrame(np.random.randn(len(idx), 2), index=idx)
_, ax = self.plt.subplots()
df.plot(ax=ax)
axis = ax.get_xaxis()
tlocs = axis.get_ticklocs()
tlabels = axis.get_ticklabels()
Reported by Pylint.
pandas/tests/io/test_sql.py
673 issues
Line: 32
Column: 1
import sqlite3
import numpy as np
import pytest
from pandas.core.dtypes.common import (
is_datetime64_dtype,
is_datetime64tz_dtype,
)
Reported by Pylint.
Line: 374
Column: 24
def teardown_method(self, method):
# if setup fails, there may not be a connection to close.
if hasattr(self, "conn"):
for tbl in self._get_all_tables():
self.drop_table(tbl)
self._close_conn()
class MySQLMixIn(MixInBase):
Reported by Pylint.
Line: 375
Column: 17
# if setup fails, there may not be a connection to close.
if hasattr(self, "conn"):
for tbl in self._get_all_tables():
self.drop_table(tbl)
self._close_conn()
class MySQLMixIn(MixInBase):
def drop_table(self, table_name):
Reported by Pylint.
Line: 376
Column: 13
if hasattr(self, "conn"):
for tbl in self._get_all_tables():
self.drop_table(tbl)
self._close_conn()
class MySQLMixIn(MixInBase):
def drop_table(self, table_name):
cur = self.conn.cursor()
Reported by Pylint.
Line: 382
Column: 45
class MySQLMixIn(MixInBase):
def drop_table(self, table_name):
cur = self.conn.cursor()
cur.execute(f"DROP TABLE IF EXISTS {sql._get_valid_mysql_name(table_name)}")
self.conn.commit()
def _get_all_tables(self):
cur = self.conn.cursor()
cur.execute("SHOW TABLES")
Reported by Pylint.
Line: 391
Column: 9
return [table[0] for table in cur.fetchall()]
def _close_conn(self):
from pymysql.err import Error
try:
self.conn.close()
except Error:
pass
Reported by Pylint.
Line: 437
Column: 13
@pytest.fixture
def load_iris_data(self, iris_path):
if not hasattr(self, "conn"):
self.setup_connect()
self.drop_table("iris")
if isinstance(self.conn, sqlite3.Connection):
create_and_load_iris_sqlite3(self.conn, iris_path)
else:
create_and_load_iris(self.conn, iris_path, self.flavor)
Reported by Pylint.
Line: 438
Column: 9
def load_iris_data(self, iris_path):
if not hasattr(self, "conn"):
self.setup_connect()
self.drop_table("iris")
if isinstance(self.conn, sqlite3.Connection):
create_and_load_iris_sqlite3(self.conn, iris_path)
else:
create_and_load_iris(self.conn, iris_path, self.flavor)
Reported by Pylint.
Line: 439
Column: 23
if not hasattr(self, "conn"):
self.setup_connect()
self.drop_table("iris")
if isinstance(self.conn, sqlite3.Connection):
create_and_load_iris_sqlite3(self.conn, iris_path)
else:
create_and_load_iris(self.conn, iris_path, self.flavor)
@pytest.fixture
Reported by Pylint.
Line: 440
Column: 42
self.setup_connect()
self.drop_table("iris")
if isinstance(self.conn, sqlite3.Connection):
create_and_load_iris_sqlite3(self.conn, iris_path)
else:
create_and_load_iris(self.conn, iris_path, self.flavor)
@pytest.fixture
def load_types_data(self, types_data):
Reported by Pylint.
pandas/tests/dtypes/test_inference.py
639 issues
Line: 22
Column: 1
import re
import numpy as np
import pytest
import pytz
from pandas._libs import (
lib,
missing as libmissing,
Reported by Pylint.
Line: 23
Column: 1
import numpy as np
import pytest
import pytz
from pandas._libs import (
lib,
missing as libmissing,
ops as libops,
Reported by Pylint.
Line: 25
Column: 1
import pytest
import pytz
from pandas._libs import (
lib,
missing as libmissing,
ops as libops,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 25
Column: 1
import pytest
import pytz
from pandas._libs import (
lib,
missing as libmissing,
ops as libops,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 25
Column: 1
import pytest
import pytz
from pandas._libs import (
lib,
missing as libmissing,
ops as libops,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 161
Column: 9
assert not is_seq(np.int64)
class A:
def __getitem__(self):
return 1
assert not is_seq(A())
Reported by Pylint.
Line: 130
Column: 23
return request.param
def test_is_list_like(maybe_list_like):
obj, expected = maybe_list_like
expected = True if expected == "set" else expected
assert inference.is_list_like(obj) == expected
Reported by Pylint.
Line: 131
Column: 10
def test_is_list_like(maybe_list_like):
obj, expected = maybe_list_like
expected = True if expected == "set" else expected
assert inference.is_list_like(obj) == expected
def test_is_list_like_disallow_sets(maybe_list_like):
Reported by Pylint.
Line: 136
Column: 37
assert inference.is_list_like(obj) == expected
def test_is_list_like_disallow_sets(maybe_list_like):
obj, expected = maybe_list_like
expected = False if expected == "set" else expected
assert inference.is_list_like(obj, allow_sets=False) == expected
Reported by Pylint.
Line: 137
Column: 10
def test_is_list_like_disallow_sets(maybe_list_like):
obj, expected = maybe_list_like
expected = False if expected == "set" else expected
assert inference.is_list_like(obj, allow_sets=False) == expected
def test_is_list_like_recursion():
Reported by Pylint.
pandas/tests/plotting/frame/test_frame.py
618 issues
Line: 12
Column: 1
import warnings
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas.core.dtypes.api import is_list_like
Reported by Pylint.
Line: 158
Column: 19
self._check_axes_shape(axes, axes_num=1, layout=(1, 1))
# When ax is supplied and required number of axes is 1,
# passed ax should be used:
fig, ax = self.plt.subplots()
axes = df.plot.bar(subplots=True, ax=ax)
assert len(axes) == 1
result = ax.axes
assert result is axes[0]
Reported by Pylint.
Line: 321
Column: 9
)
df.plot()
self.plt.axhline(y=0)
tm.close()
def test_unsorted_index(self):
df = DataFrame(
{"y": np.arange(100)}, index=np.arange(99, -1, -1), dtype=np.int64
Reported by Pylint.
Line: 523
Column: 27
def test_area_sharey_dont_overwrite(self):
# GH37942
df = DataFrame(np.random.rand(4, 2), columns=["x", "y"])
fig, (ax1, ax2) = self.plt.subplots(1, 2, sharey=True)
df.plot(ax=ax1, kind="area")
df.plot(ax=ax2, kind="area")
assert ax1._shared_y_axes.joined(ax1, ax2)
Reported by Pylint.
Line: 684
Column: 23
def test_raise_error_on_datetime_time_data(self):
# GH 8113, datetime.time type is not supported by matplotlib in scatter
df = DataFrame(np.random.randn(10), columns=["a"])
df["dtime"] = date_range(start="2014-01-01", freq="h", periods=10).time
msg = "must be a string or a number, not 'datetime.time'"
with pytest.raises(TypeError, match=msg):
df.plot(kind="scatter", x="dtime", y="a")
Reported by Pylint.
Line: 684
Column: 23
def test_raise_error_on_datetime_time_data(self):
# GH 8113, datetime.time type is not supported by matplotlib in scatter
df = DataFrame(np.random.randn(10), columns=["a"])
df["dtime"] = date_range(start="2014-01-01", freq="h", periods=10).time
msg = "must be a string or a number, not 'datetime.time'"
with pytest.raises(TypeError, match=msg):
df.plot(kind="scatter", x="dtime", y="a")
Reported by Pylint.
Line: 1397
Column: 21
df = DataFrame(np.random.rand(4, 4))
for i in range(4):
df.iloc[i, i] = np.nan
fig, axes = self.plt.subplots(ncols=4)
# GH 37668
kwargs = {}
if mpl.__version__ >= "3.3":
kwargs = {"normalize": True}
Reported by Pylint.
Line: 1914
Column: 19
# supplied ax itself is a SubplotAxes, but figure contains also
# a plain Axes object (GH11556)
fig, ax = self.plt.subplots()
fig.add_axes([0.2, 0.2, 0.2, 0.2])
Series(np.random.rand(10)).plot(ax=ax)
# supplied ax itself is a plain Axes, but because the cmap keyword
# a new ax is created for the colorbar -> also multiples axes (GH11520)
Reported by Pylint.
Line: 1921
Column: 15
# supplied ax itself is a plain Axes, but because the cmap keyword
# a new ax is created for the colorbar -> also multiples axes (GH11520)
df = DataFrame({"a": np.random.randn(8), "b": np.random.randn(8)})
fig = self.plt.figure()
ax = fig.add_axes((0, 0, 1, 1))
df.plot(kind="scatter", ax=ax, x="a", y="b", c="a", cmap="hsv")
# other examples
fig, ax = self.plt.subplots()
Reported by Pylint.
Line: 1926
Column: 19
df.plot(kind="scatter", ax=ax, x="a", y="b", c="a", cmap="hsv")
# other examples
fig, ax = self.plt.subplots()
from mpl_toolkits.axes_grid1 import make_axes_locatable
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
Series(np.random.rand(10)).plot(ax=ax)
Reported by Pylint.
pandas/tests/indexing/test_loc.py
618 issues
Line: 14
Column: 1
from dateutil.tz import gettz
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 1173
Column: 17
def test_loc_getitem_time_object(self, frame_or_series):
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
mask = (rng.hour == 9) & (rng.minute == 30)
obj = DataFrame(np.random.randn(len(rng), 3), index=rng)
if frame_or_series is Series:
obj = obj[0]
Reported by Pylint.
Line: 1173
Column: 35
def test_loc_getitem_time_object(self, frame_or_series):
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
mask = (rng.hour == 9) & (rng.minute == 30)
obj = DataFrame(np.random.randn(len(rng), 3), index=rng)
if frame_or_series is Series:
obj = obj[0]
Reported by Pylint.
Line: 1173
Column: 17
def test_loc_getitem_time_object(self, frame_or_series):
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
mask = (rng.hour == 9) & (rng.minute == 30)
obj = DataFrame(np.random.randn(len(rng), 3), index=rng)
if frame_or_series is Series:
obj = obj[0]
Reported by Pylint.
Line: 1173
Column: 35
def test_loc_getitem_time_object(self, frame_or_series):
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
mask = (rng.hour == 9) & (rng.minute == 30)
obj = DataFrame(np.random.randn(len(rng), 3), index=rng)
if frame_or_series is Series:
obj = obj[0]
Reported by Pylint.
Line: 1196
Column: 9
@pytest.mark.parametrize("dtype", [np.int64, np.float64, complex])
@td.skip_if_no_scipy
def test_loc_getitem_range_from_spmatrix(self, spmatrix_t, dtype):
import scipy.sparse
spmatrix_t = getattr(scipy.sparse, spmatrix_t)
# The bug is triggered by a sparse matrix with purely sparse columns. So the
# recipe below generates a rectangular matrix of dimension (5, 7) where all the
Reported by Pylint.
Line: 1226
Column: 9
@td.skip_if_no_scipy
def test_loc_getitem_sparse_frame(self):
# GH34687
from scipy.sparse import eye
df = DataFrame.sparse.from_spmatrix(eye(5))
result = df.loc[range(2)]
expected = DataFrame(
[[1.0, 0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0, 0.0]],
Reported by Pylint.
Line: 2399
Column: 19
idx = date_range("2011-01-01", "2011-01-02", freq="D", name="idx")
if to_period:
idx = idx.to_period("D")
ser = Series([0.1, 0.2], index=idx, name="s")
keys = [Timestamp("2011-01-01"), Timestamp("2011-01-02")]
if to_period:
keys = [x.to_period("D") for x in keys]
Reported by Pylint.
Line: 2399
Column: 19
idx = date_range("2011-01-01", "2011-01-02", freq="D", name="idx")
if to_period:
idx = idx.to_period("D")
ser = Series([0.1, 0.2], index=idx, name="s")
keys = [Timestamp("2011-01-01"), Timestamp("2011-01-02")]
if to_period:
keys = [x.to_period("D") for x in keys]
Reported by Pylint.
Line: 97
Column: 3
)
def test_loc_getitem_label_array_like(self):
# TODO: test something?
# array like
pass
def test_loc_getitem_bool(self):
# boolean indexers
Reported by Pylint.
pandas/tests/computation/test_eval.py
596 issues
Line: 9
Column: 1
import warnings
import numpy as np
import pytest
from pandas.errors import PerformanceWarning
import pandas.util._test_decorators as td
from pandas.core.dtypes.common import (
Reported by Pylint.
Line: 154
Column: 9
@classmethod
def setup_class(cls):
import numexpr as ne
cls.ne = ne
@property
def current_engines(self):
Reported by Pylint.
Line: 765
Column: 9
@classmethod
def setup_class(cls):
super().setup_class()
import numexpr as ne
cls.ne = ne
def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
ex1 = f"lhs {cmp1} mid {cmp2} rhs"
Reported by Pylint.
Line: 1318
Column: 9
df = orig_df.copy()
def f():
a = 1 # noqa
old_a = df.a.copy()
df.eval("a = a + b", inplace=True)
result = old_a + df.b
tm.assert_series_equal(result, df.a, check_names=False)
Reported by Pylint.
Line: 56
Column: 17
pytest.param(
engine,
marks=pytest.mark.skipif(
engine == "numexpr" and not USE_NUMEXPR,
reason=f"numexpr enabled->{USE_NUMEXPR}, "
f"installed->{NUMEXPR_INSTALLED}",
),
)
for engine in ENGINES
Reported by Pylint.
Line: 82
Column: 25
return request.param
def engine_has_neg_frac(engine):
return ENGINES[engine].has_neg_frac
def _eval_single_bin(lhs, cmp1, rhs, engine):
c = _binary_ops_dict[cmp1]
Reported by Pylint.
Line: 86
Column: 38
return ENGINES[engine].has_neg_frac
def _eval_single_bin(lhs, cmp1, rhs, engine):
c = _binary_ops_dict[cmp1]
if engine_has_neg_frac(engine):
try:
return c(lhs, rhs)
except ValueError as e:
Reported by Pylint.
Line: 86
Column: 33
return ENGINES[engine].has_neg_frac
def _eval_single_bin(lhs, cmp1, rhs, engine):
c = _binary_ops_dict[cmp1]
if engine_has_neg_frac(engine):
try:
return c(lhs, rhs)
except ValueError as e:
Reported by Pylint.
Line: 86
Column: 22
return ENGINES[engine].has_neg_frac
def _eval_single_bin(lhs, cmp1, rhs, engine):
c = _binary_ops_dict[cmp1]
if engine_has_neg_frac(engine):
try:
return c(lhs, rhs)
except ValueError as e:
Reported by Pylint.
Line: 100
Column: 33
return c(lhs, rhs)
def _series_and_2d_ndarray(lhs, rhs):
return (
isinstance(lhs, Series) and isinstance(rhs, np.ndarray) and rhs.ndim > 1
) or (isinstance(rhs, Series) and isinstance(lhs, np.ndarray) and lhs.ndim > 1)
Reported by Pylint.
pandas/tests/series/test_constructors.py
567 issues
Line: 10
Column: 1
from dateutil.tz import tzoffset
import numpy as np
import numpy.ma as ma
import pytest
from pandas._libs import (
iNaT,
lib,
)
Reported by Pylint.
Line: 12
Column: 1
import numpy.ma as ma
import pytest
from pandas._libs import (
iNaT,
lib,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 911
Column: 46
tm.assert_series_equal(result, expected)
# leave datetime.date alone
dates2 = np.array([d.date() for d in dates.to_pydatetime()], dtype=object)
series1 = Series(dates2, dates)
tm.assert_numpy_array_equal(series1.values, dates2)
assert series1.dtype == object
def test_constructor_dtype_datetime64_6(self):
Reported by Pylint.
Line: 911
Column: 46
tm.assert_series_equal(result, expected)
# leave datetime.date alone
dates2 = np.array([d.date() for d in dates.to_pydatetime()], dtype=object)
series1 = Series(dates2, dates)
tm.assert_numpy_array_equal(series1.values, dates2)
assert series1.dtype == object
def test_constructor_dtype_datetime64_6(self):
Reported by Pylint.
Line: 59
Column: 14
# test for None or an empty generator.
# test_constructor_pass_none tests None but only with the index also
# passed.
(lambda: Series(), True),
(lambda: Series(None), True),
(lambda: Series({}), True),
(lambda: Series(()), False), # creates a RangeIndex
(lambda: Series([]), False), # creates a RangeIndex
(lambda: Series(_ for _ in []), False), # creates a RangeIndex
Reported by Pylint.
Line: 73
Column: 3
],
)
def test_empty_constructor(self, constructor, check_index_type):
# TODO: share with frame test of the same name
with tm.assert_produces_warning(FutureWarning):
expected = Series()
result = constructor()
assert len(result.index) == 0
Reported by Pylint.
Line: 121
Column: 16
def test_constructor(self, datetime_series):
with tm.assert_produces_warning(FutureWarning):
empty_series = Series()
assert datetime_series.index._is_all_dates
# Pass in Series
derived = Series(datetime_series)
assert derived.index._is_all_dates
Reported by Pylint.
Line: 125
Column: 16
# Pass in Series
derived = Series(datetime_series)
assert derived.index._is_all_dates
assert tm.equalContents(derived.index, datetime_series.index)
# Ensure new index is not created
assert id(datetime_series.index) == id(derived.index)
Reported by Pylint.
Line: 134
Column: 16
# Mixed type Series
mixed = Series(["hello", np.NaN], index=[0, 1])
assert mixed.dtype == np.object_
assert mixed[1] is np.NaN
assert not empty_series.index._is_all_dates
with tm.assert_produces_warning(FutureWarning):
assert not Series().index._is_all_dates
Reported by Pylint.
Line: 136
Column: 20
assert mixed.dtype == np.object_
assert mixed[1] is np.NaN
assert not empty_series.index._is_all_dates
with tm.assert_produces_warning(FutureWarning):
assert not Series().index._is_all_dates
# exception raised is of type ValueError GH35744
with pytest.raises(ValueError, match="Data must be 1-dimensional"):
Reported by Pylint.