Skip to content

Commit 8ff8c32

Browse files
committed
Merge remote-tracking branch 'upstream/master' into cln_str_cat
2 parents b1a9ebe + 8a1c8ad commit 8ff8c32

File tree

7 files changed

+709
-427
lines changed

7 files changed

+709
-427
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ Deprecations
561561
- :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`)
562562
- :meth:`Series.str.cat` has deprecated using arbitrary list-likes *within* list-likes. A list-like container may still contain
563563
many ``Series``, ``Index`` or 1-dimensional ``np.ndarray``, or alternatively, only scalar values. (:issue:`21950`)
564+
- :meth:`FrozenNDArray.searchsorted` has deprecated the ``v`` parameter in favor of ``value`` (:issue:`14645`)
564565

565566
.. _whatsnew_0240.prior_deprecations:
566567

pandas/core/indexes/frozen.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import numpy as np
1212
from pandas.core.base import PandasObject
13+
from pandas.util._decorators import deprecate_kwarg
1314
from pandas.core.dtypes.cast import coerce_indexer_dtype
1415
from pandas.io.formats.printing import pprint_thing
1516

@@ -117,10 +118,10 @@ def __unicode__(self):
117118
quote_strings=True)
118119
return "%s(%s, dtype='%s')" % (type(self).__name__, prepr, self.dtype)
119120

120-
def searchsorted(self, v, side='left', sorter=None):
121+
@deprecate_kwarg(old_arg_name="v", new_arg_name="value")
122+
def searchsorted(self, value, side="left", sorter=None):
121123
"""
122-
Find indices where elements of v should be inserted
123-
in a to maintain order.
124+
Find indices to insert `value` so as to maintain order.
124125
125126
For full documentation, see `numpy.searchsorted`
126127
@@ -129,17 +130,20 @@ def searchsorted(self, v, side='left', sorter=None):
129130
numpy.searchsorted : equivalent function
130131
"""
131132

132-
# we are much more performant if the searched
133-
# indexer is the same type as the array
134-
# this doesn't matter for int64, but DOES
135-
# matter for smaller int dtypes
136-
# https://github.com/numpy/numpy/issues/5370
133+
# We are much more performant if the searched
134+
# indexer is the same type as the array.
135+
#
136+
# This doesn't matter for int64, but DOES
137+
# matter for smaller int dtypes.
138+
#
139+
# xref: https://github.com/numpy/numpy/issues/5370
137140
try:
138-
v = self.dtype.type(v)
141+
value = self.dtype.type(value)
139142
except:
140143
pass
144+
141145
return super(FrozenNDArray, self).searchsorted(
142-
v, side=side, sorter=sorter)
146+
value, side=side, sorter=sorter)
143147

144148

145149
def _ensure_frozen(array_like, categories, copy=False):

pandas/tests/frame/conftest.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import pytest
2+
3+
import numpy as np
4+
5+
from pandas import compat
6+
import pandas.util.testing as tm
7+
from pandas import DataFrame, date_range, NaT
8+
9+
10+
@pytest.fixture
11+
def float_frame():
12+
"""
13+
Fixture for DataFrame of floats with index of unique strings
14+
15+
Columns are ['A', 'B', 'C', 'D'].
16+
"""
17+
return DataFrame(tm.getSeriesData())
18+
19+
20+
@pytest.fixture
21+
def float_frame2():
22+
"""
23+
Fixture for DataFrame of floats with index of unique strings
24+
25+
Columns are ['D', 'C', 'B', 'A']
26+
"""
27+
return DataFrame(tm.getSeriesData(), columns=['D', 'C', 'B', 'A'])
28+
29+
30+
@pytest.fixture
31+
def int_frame():
32+
"""
33+
Fixture for DataFrame of ints with index of unique strings
34+
35+
Columns are ['A', 'B', 'C', 'D']
36+
"""
37+
df = DataFrame({k: v.astype(int)
38+
for k, v in compat.iteritems(tm.getSeriesData())})
39+
# force these all to int64 to avoid platform testing issues
40+
return DataFrame({c: s for c, s in compat.iteritems(df)}, dtype=np.int64)
41+
42+
43+
@pytest.fixture
44+
def datetime_frame():
45+
"""
46+
Fixture for DataFrame of floats with DatetimeIndex
47+
48+
Columns are ['A', 'B', 'C', 'D']
49+
"""
50+
return DataFrame(tm.getTimeSeriesData())
51+
52+
53+
@pytest.fixture
54+
def float_string_frame():
55+
"""
56+
Fixture for DataFrame of floats and strings with index of unique strings
57+
58+
Columns are ['A', 'B', 'C', 'D', 'foo'].
59+
"""
60+
df = DataFrame(tm.getSeriesData())
61+
df['foo'] = 'bar'
62+
return df
63+
64+
65+
@pytest.fixture
66+
def mixed_float_frame():
67+
"""
68+
Fixture for DataFrame of different float types with index of unique strings
69+
70+
Columns are ['A', 'B', 'C', 'D'].
71+
"""
72+
df = DataFrame(tm.getSeriesData())
73+
df.A = df.A.astype('float16')
74+
df.B = df.B.astype('float32')
75+
df.C = df.C.astype('float64')
76+
return df
77+
78+
79+
@pytest.fixture
80+
def mixed_float_frame2():
81+
"""
82+
Fixture for DataFrame of different float types with index of unique strings
83+
84+
Columns are ['A', 'B', 'C', 'D'].
85+
"""
86+
df = DataFrame(tm.getSeriesData())
87+
df.D = df.D.astype('float16')
88+
df.C = df.C.astype('float32')
89+
df.B = df.B.astype('float64')
90+
return df
91+
92+
93+
@pytest.fixture
94+
def mixed_int_frame():
95+
"""
96+
Fixture for DataFrame of different int types with index of unique strings
97+
98+
Columns are ['A', 'B', 'C', 'D'].
99+
"""
100+
df = DataFrame({k: v.astype(int)
101+
for k, v in compat.iteritems(tm.getSeriesData())})
102+
df.A = df.A.astype('uint8')
103+
df.B = df.B.astype('int32')
104+
df.C = df.C.astype('int64')
105+
df.D = np.ones(len(df.D), dtype='uint64')
106+
return df
107+
108+
109+
@pytest.fixture
110+
def mixed_type_frame():
111+
"""
112+
Fixture for DataFrame of float/int/string columns with RangeIndex
113+
114+
Columns are ['a', 'b', 'c', 'float32', 'int32'].
115+
"""
116+
return DataFrame({'a': 1., 'b': 2, 'c': 'foo',
117+
'float32': np.array([1.] * 10, dtype='float32'),
118+
'int32': np.array([1] * 10, dtype='int32')},
119+
index=np.arange(10))
120+
121+
122+
@pytest.fixture
123+
def timezone_frame():
124+
"""
125+
Fixture for DataFrame of date_range Series with different time zones
126+
127+
Columns are ['A', 'B', 'C']; some entries are missing
128+
"""
129+
df = DataFrame({'A': date_range('20130101', periods=3),
130+
'B': date_range('20130101', periods=3,
131+
tz='US/Eastern'),
132+
'C': date_range('20130101', periods=3,
133+
tz='CET')})
134+
df.iloc[1, 1] = NaT
135+
df.iloc[1, 2] = NaT
136+
return df
137+
138+
139+
@pytest.fixture
140+
def empty_frame():
141+
"""
142+
Fixture for empty DataFrame
143+
"""
144+
return DataFrame({})
145+
146+
147+
@pytest.fixture
148+
def datetime_series():
149+
"""
150+
Fixture for Series of floats with DatetimeIndex
151+
"""
152+
return tm.makeTimeSeries(nper=30)
153+
154+
155+
@pytest.fixture
156+
def datetime_series_short():
157+
"""
158+
Fixture for Series of floats with DatetimeIndex
159+
"""
160+
return tm.makeTimeSeries(nper=30)[5:]
161+
162+
163+
@pytest.fixture
164+
def simple_frame():
165+
"""
166+
Fixture for simple 3x3 DataFrame
167+
168+
Columns are ['one', 'two', 'three'], index is ['a', 'b', 'c'].
169+
"""
170+
arr = np.array([[1., 2., 3.],
171+
[4., 5., 6.],
172+
[7., 8., 9.]])
173+
174+
return DataFrame(arr, columns=['one', 'two', 'three'],
175+
index=['a', 'b', 'c'])
176+
177+
178+
@pytest.fixture
179+
def frame_of_index_cols():
180+
"""
181+
Fixture for DataFrame of columns that can be used for indexing
182+
183+
Columns are ['A', 'B', 'C', 'D', 'E']; 'A' & 'B' contain duplicates (but
184+
are jointly unique), the rest are unique.
185+
"""
186+
df = DataFrame({'A': ['foo', 'foo', 'foo', 'bar', 'bar'],
187+
'B': ['one', 'two', 'three', 'one', 'two'],
188+
'C': ['a', 'b', 'c', 'd', 'e'],
189+
'D': np.random.randn(5),
190+
'E': np.random.randn(5)})
191+
return df

0 commit comments

Comments
 (0)