Skip to content

Commit aee0790

Browse files
jbrockmendeljreback
authored andcommitted
CLN: assorted cleanups (pandas-dev#30473)
1 parent b3aff68 commit aee0790

File tree

11 files changed

+37
-67
lines changed

11 files changed

+37
-67
lines changed

.binstar.yml

-28
This file was deleted.

doc/source/whatsnew/v1.0.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
580580
- :meth:`Series.where` with ``Categorical`` dtype (or :meth:`DataFrame.where` with ``Categorical`` column) no longer allows setting new categories (:issue:`24114`)
581581
- :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` constructors no longer allow ``start``, ``end``, and ``periods`` keywords, use :func:`date_range`, :func:`timedelta_range`, and :func:`period_range` instead (:issue:`23919`)
582582
- :class:`DatetimeIndex` and :class:`TimedeltaIndex` constructors no longer have a ``verify_integrity`` keyword argument (:issue:`23919`)
583-
- ``pandas.core.internals.blocks.make_block`` no longer accepts the "fastpath" keyword(:issue:`19265`)
584-
- :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword(:issue:`19434`)
583+
- ``pandas.core.internals.blocks.make_block`` no longer accepts the "fastpath" keyword (:issue:`19265`)
584+
- :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword (:issue:`19434`)
585585
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)
586586
- Removed the previously deprecated :meth:`MultiIndex.to_hierarchical` (:issue:`21613`)
587587
- Removed the previously deprecated :attr:`MultiIndex.labels`, use :attr:`MultiIndex.codes` instead (:issue:`23752`)

pandas/_libs/reshape.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def unstack(reshape_t[:, :] values, uint8_t[:] mask,
2828
Py_ssize_t stride, Py_ssize_t length, Py_ssize_t width,
2929
reshape_t[:, :] new_values, uint8_t[:, :] new_mask):
3030
"""
31-
transform long sorted_values to wide new_values
31+
Transform long values to wide new_values.
3232
3333
Parameters
3434
----------

pandas/core/arrays/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,8 @@ def _add_offset(self, offset):
802802
PerformanceWarning,
803803
)
804804
result = self.astype("O") + offset
805-
if len(self) == 0:
806-
# _from_sequence won't be able to infer self.tz
805+
if not len(self):
806+
# GH#30336 _from_sequence won't be able to infer self.tz
807807
return type(self)._from_sequence(result).tz_localize(self.tz)
808808

809809
return type(self)._from_sequence(result, freq="infer")

pandas/core/internals/managers.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -741,16 +741,17 @@ def copy(self, deep=True):
741741
742742
Parameters
743743
----------
744-
deep : boolean o rstring, default True
744+
deep : bool or string, default True
745745
If False, return shallow copy (do not copy data)
746746
If 'all', copy data and a deep copy of the index
747747
748748
Returns
749749
-------
750-
copy : BlockManager
750+
BlockManager
751751
"""
752752
# this preserves the notion of view copying of axes
753753
if deep:
754+
# hit in e.g. tests.io.json.test_pandas
754755

755756
def copy_func(ax):
756757
if deep == "all":
@@ -761,6 +762,7 @@ def copy_func(ax):
761762
new_axes = [copy_func(ax) for ax in self.axes]
762763
else:
763764
new_axes = list(self.axes)
765+
764766
res = self.apply("copy", deep=deep)
765767
res.axes = new_axes
766768
return res

pandas/io/parsers.py

-2
Original file line numberDiff line numberDiff line change
@@ -2204,8 +2204,6 @@ class PythonParser(ParserBase):
22042204
def __init__(self, f, **kwds):
22052205
"""
22062206
Workhorse function for processing nested list into DataFrame
2207-
2208-
Should be replaced by np.genfromtxt eventually?
22092207
"""
22102208
ParserBase.__init__(self, kwds)
22112209

pandas/plotting/_matplotlib/core.py

-6
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ def _iter_data(self, data=None, keep_index=False, fillna=None):
241241
if fillna is not None:
242242
data = data.fillna(fillna)
243243

244-
# TODO: unused?
245-
# if self.sort_columns:
246-
# columns = com.try_sort(data.columns)
247-
# else:
248-
# columns = data.columns
249-
250244
for col, values in data.items():
251245
if keep_index is True:
252246
yield col, values

pandas/tests/computation/test_eval.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -1206,25 +1206,33 @@ def test_truediv(self):
12061206
ex = "s / 1"
12071207
d = {"s": s} # noqa
12081208

1209-
res = self.eval(ex, truediv=False)
1209+
# FutureWarning: The `truediv` parameter in pd.eval is deprecated and will be
1210+
# removed in a future version.
1211+
with tm.assert_produces_warning(FutureWarning):
1212+
res = self.eval(ex, truediv=False)
12101213
tm.assert_numpy_array_equal(res, np.array([1.0]))
12111214

1212-
res = self.eval(ex, truediv=True)
1215+
with tm.assert_produces_warning(FutureWarning):
1216+
res = self.eval(ex, truediv=True)
12131217
tm.assert_numpy_array_equal(res, np.array([1.0]))
12141218

1215-
res = self.eval("1 / 2", truediv=True)
1219+
with tm.assert_produces_warning(FutureWarning):
1220+
res = self.eval("1 / 2", truediv=True)
12161221
expec = 0.5
12171222
assert res == expec
12181223

1219-
res = self.eval("1 / 2", truediv=False)
1224+
with tm.assert_produces_warning(FutureWarning):
1225+
res = self.eval("1 / 2", truediv=False)
12201226
expec = 0.5
12211227
assert res == expec
12221228

1223-
res = self.eval("s / 2", truediv=False)
1229+
with tm.assert_produces_warning(FutureWarning):
1230+
res = self.eval("s / 2", truediv=False)
12241231
expec = 0.5
12251232
assert res == expec
12261233

1227-
res = self.eval("s / 2", truediv=True)
1234+
with tm.assert_produces_warning(FutureWarning):
1235+
res = self.eval("s / 2", truediv=True)
12281236
expec = 0.5
12291237
assert res == expec
12301238

pandas/tests/dtypes/test_inference.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
"""
66
import collections
7+
from collections import namedtuple
78
from datetime import date, datetime, time, timedelta
89
from decimal import Decimal
910
from fractions import Fraction
@@ -1123,18 +1124,13 @@ def test_is_string_array(self):
11231124
def test_to_object_array_tuples(self):
11241125
r = (5, 6)
11251126
values = [r]
1126-
result = lib.to_object_array_tuples(values)
1127+
lib.to_object_array_tuples(values)
11271128

1128-
try:
1129-
# make sure record array works
1130-
from collections import namedtuple
1131-
1132-
record = namedtuple("record", "x y")
1133-
r = record(5, 6)
1134-
values = [r]
1135-
result = lib.to_object_array_tuples(values) # noqa
1136-
except ImportError:
1137-
pass
1129+
# make sure record array works
1130+
record = namedtuple("record", "x y")
1131+
r = record(5, 6)
1132+
values = [r]
1133+
lib.to_object_array_tuples(values)
11381134

11391135
def test_object(self):
11401136

@@ -1174,8 +1170,6 @@ def test_is_period(self):
11741170
def test_categorical(self):
11751171

11761172
# GH 8974
1177-
from pandas import Categorical, Series
1178-
11791173
arr = Categorical(list("abc"))
11801174
result = lib.infer_dtype(arr, skipna=True)
11811175
assert result == "categorical"

pandas/tests/extension/test_numpy.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def data_missing(allow_in_pandas, dtype):
5151
if dtype.numpy_dtype == "object":
5252
if _np_version_under1p16:
5353
raise pytest.skip("Skipping for NumPy <1.16")
54-
return PandasArray(np.array([np.nan, (1,)]))
54+
return PandasArray(np.array([np.nan, (1,)], dtype=object))
5555
return PandasArray(np.array([np.nan, 1.0]))
5656

5757

@@ -78,7 +78,7 @@ def data_for_sorting(allow_in_pandas, dtype):
7878
if dtype.numpy_dtype == "object":
7979
# Use an empty tuple for first element, then remove,
8080
# to disable np.array's shape inference.
81-
return PandasArray(np.array([(), (2,), (3,), (1,)])[1:])
81+
return PandasArray(np.array([(), (2,), (3,), (1,)], dtype=object)[1:])
8282
return PandasArray(np.array([1, 2, 0]))
8383

8484

@@ -90,7 +90,7 @@ def data_missing_for_sorting(allow_in_pandas, dtype):
9090
A < B and NA missing.
9191
"""
9292
if dtype.numpy_dtype == "object":
93-
return PandasArray(np.array([(1,), np.nan, (0,)]))
93+
return PandasArray(np.array([(1,), np.nan, (0,)], dtype=object))
9494
return PandasArray(np.array([1, np.nan, 0]))
9595

9696

@@ -106,7 +106,9 @@ def data_for_grouping(allow_in_pandas, dtype):
106106
a, b, c = (1,), (2,), (3,)
107107
else:
108108
a, b, c = np.arange(3)
109-
return PandasArray(np.array([b, b, np.nan, np.nan, a, a, b, c]))
109+
return PandasArray(
110+
np.array([b, b, np.nan, np.nan, a, a, b, c], dtype=dtype.numpy_dtype)
111+
)
110112

111113

112114
@pytest.fixture

pandas/tests/frame/methods/test_to_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_to_records_with_unicode_index(self):
7474
tm.assert_almost_equal(result, expected)
7575

7676
def test_to_records_with_unicode_column_names(self):
77-
# xref GH#2407
77+
# xref issue: https://github.com/numpy/numpy/issues/2407
7878
# Issue GH#11879. to_records used to raise an exception when used
7979
# with column names containing non-ascii characters in Python 2
8080
result = DataFrame(data={"accented_name_é": [1.0]}).to_records()

0 commit comments

Comments
 (0)