Skip to content

Commit d35db71

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into fuse_kh
2 parents e99cf18 + 0df22b6 commit d35db71

File tree

11 files changed

+39
-37
lines changed

11 files changed

+39
-37
lines changed

pandas/_libs/hashtable_class_helper.pxi.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ cdef class PyObjectHashTable(HashTable):
925925
return self.table.size
926926

927927
def __contains__(self, object key):
928-
cdef khiter_t k
928+
cdef:
929+
khiter_t k
929930
hash(key)
930931

931932
k = kh_get_pymap(self.table, <PyObject*>key)
@@ -938,7 +939,8 @@ cdef class PyObjectHashTable(HashTable):
938939
sizeof(uint32_t)) # flags
939940

940941
cpdef get_item(self, object val):
941-
cdef khiter_t k
942+
cdef:
943+
khiter_t k
942944

943945
k = kh_get_pymap(self.table, <PyObject*>val)
944946
if k != self.table.n_buckets:

pandas/_libs/hashtable_func_helper.pxi.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ cdef inline khiter_t kh_get(table_t *table, scalar_t val) nogil:
8282

8383
{{py:
8484

85-
# dtype, ttype
85+
# dtype, ttype, c_type
8686
dtypes = [('float64', 'float64', 'float64_t'),
8787
('uint64', 'uint64', 'uint64_t'),
8888
('object', 'pymap', 'object'),
@@ -284,7 +284,6 @@ def ismember_{{dtype}}(ndarray[{{c_type}}] arr, ndarray[{{c_type}}] values):
284284
{{else}}
285285
def ismember_{{dtype}}({{c_type}}[:] arr, {{c_type}}[:] values):
286286
{{endif}}
287-
288287
"""
289288
Return boolean of values in arr on an
290289
element by-element basis

pandas/_libs/internals.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ cdef slice_get_indices_ex(slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX):
284284
return start, stop, step, length
285285

286286

287-
def slice_getitem(slice slc not None, ind):
287+
cdef slice_getitem(slice slc, ind):
288288
cdef:
289289
Py_ssize_t s_start, s_stop, s_step, s_len
290290
Py_ssize_t ind_start, ind_stop, ind_step, ind_len

pandas/_libs/interval.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cnp.import_array()
1818

1919
cimport pandas._libs.util as util
2020

21-
from pandas._libs.hashtable cimport Int64Vector, Int64VectorData
21+
from pandas._libs.hashtable cimport Int64Vector
2222
from pandas._libs.tslibs.util cimport is_integer_object, is_float_object
2323

2424
from pandas._libs.tslibs import Timestamp

pandas/_libs/lib.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ import warnings
99
import cython
1010
from cython import Py_ssize_t
1111

12-
from cpython.list cimport PyList_New
13-
from cpython.object cimport (PyObject_Str, PyObject_RichCompareBool, Py_EQ,
14-
Py_SIZE)
12+
from cpython.object cimport PyObject_RichCompareBool, Py_EQ
1513
from cpython.ref cimport Py_INCREF
1614
from cpython.tuple cimport PyTuple_SET_ITEM, PyTuple_New
17-
from cpython.unicode cimport PyUnicode_Join
1815

1916
from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
2017
PyTime_Check, PyDelta_Check,

pandas/core/dtypes/cast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def trans(x):
202202
r = result.ravel()
203203
arr = np.array([r[0]])
204204

205-
if isna(arr).any() or not np.allclose(arr, trans(arr).astype(dtype), rtol=0):
205+
if isna(arr).any():
206206
# if we have any nulls, then we are done
207207
return result
208208

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10852,7 +10852,7 @@ def transform(self, func, *args, **kwargs):
1085210852
Also returns None for empty %(klass)s.
1085310853
"""
1085410854

10855-
def _find_valid_index(self, how):
10855+
def _find_valid_index(self, how: str):
1085610856
"""
1085710857
Retrieves the index of the first valid value.
1085810858

pandas/core/groupby/generic.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def aggregate(self, func=None, *args, **kwargs):
262262

263263
try:
264264
return self._python_agg_general(func, *args, **kwargs)
265-
except AssertionError:
265+
except (AssertionError, TypeError):
266266
raise
267267
except Exception:
268268
result = self._aggregate_named(func, *args, **kwargs)
@@ -1099,10 +1099,7 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
10991099

11001100
cast = self._transform_should_cast(func)
11011101
try:
1102-
11031102
result[item] = colg.aggregate(func, *args, **kwargs)
1104-
if cast:
1105-
result[item] = self._try_cast(result[item], data)
11061103

11071104
except ValueError as err:
11081105
if "Must produce aggregated value" in str(err):
@@ -1111,10 +1108,10 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
11111108
raise
11121109
cannot_agg.append(item)
11131110
continue
1114-
except TypeError as e:
1115-
cannot_agg.append(item)
1116-
errors = e
1117-
continue
1111+
1112+
else:
1113+
if cast:
1114+
result[item] = self._try_cast(result[item], data)
11181115

11191116
result_columns = obj.columns
11201117
if cannot_agg:

pandas/core/util/hashing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import numpy as np
77

8+
from pandas._libs import Timestamp
89
import pandas._libs.hashing as hashing
9-
import pandas._libs.tslibs as tslibs
1010

1111
from pandas.core.dtypes.cast import infer_dtype_from_scalar
1212
from pandas.core.dtypes.common import (
@@ -337,8 +337,8 @@ def _hash_scalar(val, encoding: str = "utf8", hash_key=None):
337337
# for tz-aware datetimes, we need the underlying naive UTC value and
338338
# not the tz aware object or pd extension type (as
339339
# infer_dtype_from_scalar would do)
340-
if not isinstance(val, tslibs.Timestamp):
341-
val = tslibs.Timestamp(val)
340+
if not isinstance(val, Timestamp):
341+
val = Timestamp(val)
342342
val = val.tz_convert(None)
343343

344344
dtype, val = infer_dtype_from_scalar(val)

pandas/tests/dtypes/cast/test_downcast.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import decimal
2+
13
import numpy as np
24
import pytest
35

@@ -25,6 +27,13 @@
2527
"infer",
2628
np.array([8, 8, 8, 8, 9], dtype=np.int64),
2729
),
30+
(
31+
# This is a judgement call, but we do _not_ downcast Decimal
32+
# objects
33+
np.array([decimal.Decimal(0.0)]),
34+
"int64",
35+
np.array([decimal.Decimal(0.0)]),
36+
),
2837
],
2938
)
3039
def test_downcast(arr, expected, dtype):

pandas/tests/series/test_repr.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
from pandas.core.index import MultiIndex
1818
import pandas.util.testing as tm
1919

20-
from .common import TestData
2120

22-
23-
class TestSeriesRepr(TestData):
21+
class TestSeriesRepr:
2422
def test_multilevel_name_print(self):
2523
index = MultiIndex(
2624
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
@@ -67,24 +65,24 @@ def test_name_printing(self):
6765
s = Series(index=date_range("20010101", "20020101"), name="test")
6866
assert "Name: test" in repr(s)
6967

70-
def test_repr(self):
71-
str(self.ts)
72-
str(self.series)
73-
str(self.series.astype(int))
74-
str(self.objSeries)
68+
def test_repr(self, datetime_series, string_series, object_series):
69+
str(datetime_series)
70+
str(string_series)
71+
str(string_series.astype(int))
72+
str(object_series)
7573

7674
str(Series(tm.randn(1000), index=np.arange(1000)))
7775
str(Series(tm.randn(1000), index=np.arange(1000, 0, step=-1)))
7876

7977
# empty
80-
str(self.empty)
78+
str(Series())
8179

8280
# with NaNs
83-
self.series[5:7] = np.NaN
84-
str(self.series)
81+
string_series[5:7] = np.NaN
82+
str(string_series)
8583

8684
# with Nones
87-
ots = self.ts.astype("O")
85+
ots = datetime_series.astype("O")
8886
ots[::2] = None
8987
repr(ots)
9088

@@ -102,8 +100,8 @@ def test_repr(self):
102100
("\u03B1", "\u03B2", "\u03B3"),
103101
("\u03B1", "bar"),
104102
]:
105-
self.series.name = name
106-
repr(self.series)
103+
string_series.name = name
104+
repr(string_series)
107105

108106
biggie = Series(
109107
tm.randn(1000), index=np.arange(1000), name=("foo", "bar", "baz")

0 commit comments

Comments
 (0)