Skip to content

Commit 80e9caf

Browse files
committed
Additional fixes
1 parent 0f2b03a commit 80e9caf

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

pandas/indexes/base.py

+7
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
194194
return result.asobject
195195
else:
196196
return result
197+
elif is_period_dtype(data):
198+
from pandas.tseries.period import PeriodIndex
199+
result = PeriodIndex(data, copy=copy, name=name, **kwargs)
200+
if dtype is not None and _o_dtype == dtype:
201+
return result.asobject
202+
else:
203+
return result
197204

198205
if dtype is not None:
199206
try:

pandas/io/tests/test_feather.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_unsupported(self):
8484

8585
# period
8686
df = pd.DataFrame({'a': pd.period_range('2013', freq='M', periods=3)})
87-
self.check_error_on_write(df, ValueError)
87+
self.check_error_on_write(df, feather.FeatherError)
8888

8989
# non-strings
9090
df = pd.DataFrame({'a': ['a', 1, 2.0]})

pandas/src/hashtable_class_helper.pxi.in

+36
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ cdef class ObjectVector:
181181
def __len__(self):
182182
return self.n
183183

184+
@cython.wraparound(False)
185+
@cython.boundscheck(False)
184186
cdef inline append(self, object o):
185187
if self.n == self.m:
186188
self.m = max(self.m * 2, _INIT_VEC_CAP)
@@ -237,6 +239,8 @@ cdef class {{name}}HashTable(HashTable):
237239
k = kh_get_{{dtype}}(self.table, key)
238240
return k != self.table.n_buckets
239241

242+
@cython.wraparound(False)
243+
@cython.boundscheck(False)
240244
cpdef get_item(self, {{dtype}}_t val):
241245
cdef khiter_t k
242246
k = kh_get_{{dtype}}(self.table, val)
@@ -245,13 +249,17 @@ cdef class {{name}}HashTable(HashTable):
245249
else:
246250
raise KeyError(val)
247251

252+
@cython.wraparound(False)
253+
@cython.boundscheck(False)
248254
def get_iter_test(self, {{dtype}}_t key, Py_ssize_t iterations):
249255
cdef Py_ssize_t i, val=0
250256
for i in range(iterations):
251257
k = kh_get_{{dtype}}(self.table, val)
252258
if k != self.table.n_buckets:
253259
val = self.table.vals[k]
254260

261+
@cython.wraparound(False)
262+
@cython.boundscheck(False)
255263
cpdef set_item(self, {{dtype}}_t key, Py_ssize_t val):
256264
cdef:
257265
khiter_t k
@@ -264,6 +272,7 @@ cdef class {{name}}HashTable(HashTable):
264272
else:
265273
raise KeyError(key)
266274

275+
@cython.wraparound(False)
267276
@cython.boundscheck(False)
268277
def map(self, {{dtype}}_t[:] keys, int64_t[:] values):
269278
cdef:
@@ -278,6 +287,7 @@ cdef class {{name}}HashTable(HashTable):
278287
k = kh_put_{{dtype}}(self.table, key, &ret)
279288
self.table.vals[k] = <Py_ssize_t> values[i]
280289

290+
@cython.wraparound(False)
281291
@cython.boundscheck(False)
282292
def map_locations(self, ndarray[{{dtype}}_t, ndim=1] values):
283293
cdef:
@@ -292,6 +302,7 @@ cdef class {{name}}HashTable(HashTable):
292302
k = kh_put_{{dtype}}(self.table, val, &ret)
293303
self.table.vals[k] = i
294304

305+
@cython.wraparound(False)
295306
@cython.boundscheck(False)
296307
def lookup(self, {{dtype}}_t[:] values):
297308
cdef:
@@ -317,6 +328,7 @@ cdef class {{name}}HashTable(HashTable):
317328
labels = self.get_labels(values, uniques, 0, 0)
318329
return uniques.to_array(), labels
319330

331+
@cython.wraparound(False)
320332
@cython.boundscheck(False)
321333
def get_labels(self, {{dtype}}_t[:] values, {{name}}Vector uniques,
322334
Py_ssize_t count_prior, Py_ssize_t na_sentinel,
@@ -359,6 +371,7 @@ cdef class {{name}}HashTable(HashTable):
359371

360372
return np.asarray(labels)
361373

374+
@cython.wraparound(False)
362375
@cython.boundscheck(False)
363376
def get_labels_groupby(self, {{dtype}}_t[:] values):
364377
cdef:
@@ -402,6 +415,7 @@ cdef class {{name}}HashTable(HashTable):
402415

403416
return np.asarray(labels), arr_uniques
404417

418+
@cython.wraparound(False)
405419
@cython.boundscheck(False)
406420
def unique(self, {{dtype}}_t[:] values):
407421
cdef:
@@ -464,6 +478,8 @@ cdef class StringHashTable(HashTable):
464478
kh_destroy_str(self.table)
465479
self.table = NULL
466480

481+
@cython.wraparound(False)
482+
@cython.boundscheck(False)
467483
cpdef get_item(self, object val):
468484
cdef:
469485
khiter_t k
@@ -476,6 +492,8 @@ cdef class StringHashTable(HashTable):
476492
else:
477493
raise KeyError(val)
478494

495+
@cython.wraparound(False)
496+
@cython.boundscheck(False)
479497
def get_iter_test(self, object key, Py_ssize_t iterations):
480498
cdef:
481499
Py_ssize_t i, val
@@ -488,6 +506,8 @@ cdef class StringHashTable(HashTable):
488506
if k != self.table.n_buckets:
489507
val = self.table.vals[k]
490508

509+
@cython.wraparound(False)
510+
@cython.boundscheck(False)
491511
cpdef set_item(self, object key, Py_ssize_t val):
492512
cdef:
493513
khiter_t k
@@ -503,6 +523,7 @@ cdef class StringHashTable(HashTable):
503523
else:
504524
raise KeyError(key)
505525

526+
@cython.wraparound(False)
506527
@cython.boundscheck(False)
507528
def get_indexer(self, ndarray[object] values):
508529
cdef:
@@ -531,6 +552,7 @@ cdef class StringHashTable(HashTable):
531552
free(vecs)
532553
return labels
533554

555+
@cython.wraparound(False)
534556
@cython.boundscheck(False)
535557
def unique(self, ndarray[object] values):
536558
cdef:
@@ -567,6 +589,8 @@ cdef class StringHashTable(HashTable):
567589
uniques.append(values[uindexer[i]])
568590
return uniques.to_array()
569591

592+
@cython.wraparound(False)
593+
@cython.boundscheck(False)
570594
def factorize(self, ndarray[object] values):
571595
uniques = ObjectVector()
572596
labels = self.get_labels(values, uniques, 0, 0)
@@ -724,6 +748,8 @@ cdef class PyObjectHashTable(HashTable):
724748
else:
725749
raise KeyError(val)
726750

751+
@cython.wraparound(False)
752+
@cython.boundscheck(False)
727753
def get_iter_test(self, object key, Py_ssize_t iterations):
728754
cdef Py_ssize_t i, val
729755
if key != key or key is None:
@@ -733,6 +759,8 @@ cdef class PyObjectHashTable(HashTable):
733759
if k != self.table.n_buckets:
734760
val = self.table.vals[k]
735761

762+
@cython.wraparound(False)
763+
@cython.boundscheck(False)
736764
cpdef set_item(self, object key, Py_ssize_t val):
737765
cdef:
738766
khiter_t k
@@ -749,6 +777,8 @@ cdef class PyObjectHashTable(HashTable):
749777
else:
750778
raise KeyError(key)
751779

780+
@cython.wraparound(False)
781+
@cython.boundscheck(False)
752782
def map_locations(self, ndarray[object] values):
753783
cdef:
754784
Py_ssize_t i, n = len(values)
@@ -765,6 +795,8 @@ cdef class PyObjectHashTable(HashTable):
765795
k = kh_put_pymap(self.table, <PyObject*>val, &ret)
766796
self.table.vals[k] = i
767797

798+
@cython.wraparound(False)
799+
@cython.boundscheck(False)
768800
def lookup(self, ndarray[object] values):
769801
cdef:
770802
Py_ssize_t i, n = len(values)
@@ -787,6 +819,8 @@ cdef class PyObjectHashTable(HashTable):
787819

788820
return np.asarray(locs)
789821

822+
@cython.wraparound(False)
823+
@cython.boundscheck(False)
790824
def unique(self, ndarray[object] values):
791825
cdef:
792826
Py_ssize_t i, n = len(values)
@@ -810,6 +844,8 @@ cdef class PyObjectHashTable(HashTable):
810844

811845
return uniques.to_array()
812846

847+
@cython.wraparound(False)
848+
@cython.boundscheck(False)
813849
def get_labels(self, ndarray[object] values, ObjectVector uniques,
814850
Py_ssize_t count_prior, int64_t na_sentinel,
815851
bint check_null=True):

pandas/tseries/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from pandas import compat
4242
from pandas.util.decorators import (Appender, Substitution, cache_readonly,
4343
deprecate_kwarg)
44-
from pandas.lib import infer_dtype
44+
import pandas.lib as lib
4545
import pandas.tslib as tslib
4646
from pandas.compat import zip, u
4747

@@ -278,7 +278,7 @@ def _from_arraylike(cls, data, freq, tz):
278278
base1, base2, 1)
279279
else:
280280
if is_object_dtype(data):
281-
inferred = infer_dtype(data)
281+
inferred = lib.infer_dtype(data)
282282
if inferred == 'integer':
283283
data = data.astype(np.int64)
284284

pandas/types/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def is_datetimetz(array):
7373

7474
def is_period(array):
7575
""" return if we are a period array """
76-
return is_period_dtype(array) # or is_period_arraylike(array)
76+
return is_period_dtype(array)
7777

7878

7979
def is_datetime64_dtype(arr_or_dtype):

0 commit comments

Comments
 (0)