From 47df2cd1fd106259d6a09c37bed39aa8488fd6ea Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 21 Mar 2020 22:53:35 +0200 Subject: [PATCH 1/2] CLN: Avoiding casting --- pandas/_libs/tslibs/parsing.pyx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index ebdf7a1e29216..dadbdddcf4d2f 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -577,8 +577,9 @@ def try_parse_date_and_time(object[:] dates, object[:] times, object[:] result n = len(dates) - # Cast to avoid build warning see GH#26757 - if len(times) != n: + # TODO(cython 3.0): + # Instead of `times.shape[0]` use `len(times)` + if times.shape[0] != n: raise ValueError('Length of dates and times must be equal') result = np.empty(n, dtype='O') @@ -614,8 +615,10 @@ def try_parse_year_month_day(object[:] years, object[:] months, object[:] result n = len(years) - # Cast to avoid build warning see GH#26757 - if len(months) != n or len(days) != n: + # TODO(cython 3.0): + # Instead of `months.shape[0]` use `len(months)` + # Instead of `days.shape[0]` use `len(days)` + if months.shape[0] != n or days.shape[0] != n: raise ValueError('Length of years/months/days must all be equal') result = np.empty(n, dtype='O') @@ -640,10 +643,19 @@ def try_parse_datetime_components(object[:] years, double micros n = len(years) - # Cast to avoid build warning see GH#26757 - if (len(months) != n or len(days) != n or - len(hours) != n or len(minutes) != n or - len(seconds) != n): + # TODO(cython 3.0): + # Instead of `months.shape[0]` use `len(months)` + # Instead of `days.shape[0]` use `len(days)` + # Instead of `hours.shape[0]` use `len(hours)` + # Instead of `minutes.shape[0]` use `len(minutes)` + # Instead of `seconds.shape[0]` use `len(seconds)` + if ( + months.shape[0] != n + or days.shape[0] != n + or hours.shape[0] != n + or minutes.shape[0] != n + or seconds.shape[0] != n + ): raise ValueError('Length of all datetime components must be equal') result = np.empty(n, dtype='O') From e36b7653ad606e485248854019a2d3d8d4beb0ef Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 22 Mar 2020 00:57:30 +0200 Subject: [PATCH 2/2] Change comments REF: https://github.com/pandas-dev/pandas/pull/32897#issuecomment-602115389 --- pandas/_libs/tslibs/parsing.pyx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index dadbdddcf4d2f..51202eea60a25 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -577,8 +577,7 @@ def try_parse_date_and_time(object[:] dates, object[:] times, object[:] result n = len(dates) - # TODO(cython 3.0): - # Instead of `times.shape[0]` use `len(times)` + # TODO(cython 3.0): Use len instead of `shape[0]` if times.shape[0] != n: raise ValueError('Length of dates and times must be equal') result = np.empty(n, dtype='O') @@ -615,9 +614,7 @@ def try_parse_year_month_day(object[:] years, object[:] months, object[:] result n = len(years) - # TODO(cython 3.0): - # Instead of `months.shape[0]` use `len(months)` - # Instead of `days.shape[0]` use `len(days)` + # TODO(cython 3.0): Use len instead of `shape[0]` if months.shape[0] != n or days.shape[0] != n: raise ValueError('Length of years/months/days must all be equal') result = np.empty(n, dtype='O') @@ -643,12 +640,7 @@ def try_parse_datetime_components(object[:] years, double micros n = len(years) - # TODO(cython 3.0): - # Instead of `months.shape[0]` use `len(months)` - # Instead of `days.shape[0]` use `len(days)` - # Instead of `hours.shape[0]` use `len(hours)` - # Instead of `minutes.shape[0]` use `len(minutes)` - # Instead of `seconds.shape[0]` use `len(seconds)` + # TODO(cython 3.0): Use len instead of `shape[0]` if ( months.shape[0] != n or days.shape[0] != n