@@ -2352,34 +2352,31 @@ cdef inline object convert_to_unicode(object item,
2352
2352
2353
2353
@ cython.wraparound (False )
2354
2354
@ cython.boundscheck (False )
2355
- cdef cnp.ndarray[object ] _concat_date_cols_numpy(tuple date_cols,
2356
- Py_ssize_t rows_count,
2357
- Py_ssize_t col_count,
2358
- bint keep_trivial_numbers):
2355
+ def _concat_date_cols (tuple date_cols , bint keep_trivial_numbers = True ):
2359
2356
"""
2360
- Concatenates elements from numpy arrays into strings.
2357
+ Concatenates elements from numpy arrays in `date_cols` into strings.
2361
2358
2362
2359
Parameters
2363
2360
----------
2364
2361
date_cols : tuple of numpy arrays
2365
- rows_count : Py_ssize_t
2366
- count of elements from arrays that will be concatenated
2367
- col_count : Py_ssize_t
2368
- count of arrays whose elements will be concatenated
2369
- keep_trivial_numbers : bool, default False
2362
+ keep_trivial_numbers : bool, default True
2370
2363
if True and len(date_cols) == 1, then
2371
2364
conversion (to string from integer/float zero) is not performed
2372
2365
2373
2366
Returns
2374
2367
-------
2375
2368
arr_of_rows : ndarray (dtype=object)
2376
2369
2377
- Notes
2378
- -----
2379
- This function speeds up concatenation for numpy arrays.
2380
- You also can use `_concat_date_cols_sequence` function.
2370
+ Examples
2371
+ --------
2372
+ >>> dates=np.array(['3/31/2019', '4/31/2019'], dtype=object)
2373
+ >>> times=np.array(['11:20', '10:45'], dtype=object)
2374
+ >>> result = _concat_date_cols((dates, times))
2375
+ >>> result
2376
+ array(['3/31/2019 11:20', '4/31/2019 10:45'], dtype=object)
2381
2377
"""
2382
2378
cdef:
2379
+ Py_ssize_t rows_count = 0 , col_count = len (date_cols)
2383
2380
Py_ssize_t col_idx, row_idx
2384
2381
list list_to_join
2385
2382
cnp.ndarray[object ] iters
@@ -2388,6 +2385,14 @@ cdef cnp.ndarray[object] _concat_date_cols_numpy(tuple date_cols,
2388
2385
cnp.ndarray[object ] result
2389
2386
object [:] result_view
2390
2387
2388
+ if col_count == 0 :
2389
+ return np.zeros(0 , dtype = object )
2390
+
2391
+
2392
+ if not all (util.is_array(array) for array in date_cols):
2393
+ raise ValueError (" not all elements from date_cols are numpy arrays" )
2394
+
2395
+ rows_count = min (len (array) for array in date_cols)
2391
2396
result = np.zeros(rows_count, dtype = object )
2392
2397
result_view = result
2393
2398
@@ -2422,40 +2427,3 @@ cdef cnp.ndarray[object] _concat_date_cols_numpy(tuple date_cols,
2422
2427
result_view[row_idx] = PyUnicode_Join(' ' , list_to_join)
2423
2428
2424
2429
return result
2425
-
2426
-
2427
- def _concat_date_cols (tuple date_cols , bint keep_trivial_numbers = True ):
2428
- """
2429
- Concatenates elements from numpy arrays in `date_cols` into strings.
2430
-
2431
- Parameters
2432
- ----------
2433
- date_cols : tuple of sequences
2434
- keep_trivial_numbers : bool, default True
2435
- if True and len(date_cols) == 1, then
2436
- conversion (to string from integer/float zero) is not performed
2437
-
2438
- Returns
2439
- -------
2440
- arr_of_rows : ndarray (dtype=object)
2441
-
2442
- Examples
2443
- --------
2444
- >>> dates=np.array(['3/31/2019', '4/31/2019'], dtype=object)
2445
- >>> times=np.array(['11:20', '10:45'], dtype=object)
2446
- >>> result = _concat_date_cols((dates, times))
2447
- >>> result
2448
- array(['3/31/2019 11:20', '4/31/2019 10:45'], dtype=object)
2449
- """
2450
- cdef:
2451
- Py_ssize_t rows_count = 0 , col_count = len (date_cols)
2452
-
2453
- if col_count == 0 :
2454
- return np.zeros(0 , dtype = object )
2455
-
2456
- rows_count = min (len (array) for array in date_cols)
2457
-
2458
- if all (util.is_array(array) for array in date_cols):
2459
- return _concat_date_cols_numpy(date_cols, rows_count, col_count,
2460
- keep_trivial_numbers)
2461
- raise ValueError (" not all elements from date_cols are numpy arrays" )
0 commit comments