From 1ea71f8649725327c13435c882f1f65f4c063b8b Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 8 Feb 2020 15:38:46 +0200 Subject: [PATCH 1/8] CLN: some code cleanups in pandas/_libs/ --- pandas/_libs/algos.pyx | 31 ++++++++++---- pandas/_libs/join.pyx | 20 +++++++-- pandas/_libs/lib.pyx | 70 ++++++++++++++++++------------- pandas/_libs/reshape.pyx | 20 +++++++-- pandas/_libs/sparse.pyx | 4 +- pandas/_libs/tslibs/period.pyx | 63 +++++++++++++++------------- pandas/_libs/tslibs/strptime.pyx | 11 ++--- pandas/_libs/tslibs/timezones.pyx | 4 +- 8 files changed, 139 insertions(+), 84 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index dd1f38ce3a842..ec66683a906cc 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -7,13 +7,30 @@ from libc.math cimport fabs, sqrt import numpy as np cimport numpy as cnp -from numpy cimport (ndarray, - NPY_INT64, NPY_INT32, NPY_INT16, NPY_INT8, - NPY_UINT64, NPY_UINT32, NPY_UINT16, NPY_UINT8, - NPY_FLOAT32, NPY_FLOAT64, - NPY_OBJECT, - int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, - uint32_t, uint64_t, float32_t, float64_t) +from numpy cimport ( + NPY_FLOAT32, + NPY_FLOAT64, + NPY_INT8, + NPY_INT16, + NPY_INT32, + NPY_INT64, + NPY_OBJECT, + NPY_UINT8, + NPY_UINT16, + NPY_UINT32, + NPY_UINT64, + float32_t, + float64_t, + int8_t, + int16_t, + int32_t, + int64_t, + ndarray, + uint8_t, + uint16_t, + uint32_t, + uint64_t, +) cnp.import_array() diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index 093c53790cd35..dfa7aa708d681 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -3,13 +3,25 @@ from cython import Py_ssize_t import numpy as np cimport numpy as cnp -from numpy cimport (ndarray, - int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, - uint32_t, uint64_t, float32_t, float64_t) +from numpy cimport ( + float32_t, + float64_t, + int8_t, + int16_t, + int32_t, + int64_t, + ndarray, + uint8_t, + uint16_t, + uint32_t, + uint64_t, +) cnp.import_array() from pandas._libs.algos import ( - groupsort_indexer, ensure_platform_int, take_1d_int64_int64 + ensure_platform_int, + groupsort_indexer, + take_1d_int64_int64, ) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 9702eb4615909..8a62282fbb8c3 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -15,18 +15,33 @@ from cpython.iterator cimport PyIter_Check from cpython.sequence cimport PySequence_Check from cpython.number cimport PyNumber_Check -from cpython.datetime cimport (PyDateTime_Check, PyDate_Check, - PyTime_Check, PyDelta_Check, - PyDateTime_IMPORT) +from cpython.datetime cimport ( + PyDateTime_Check, + PyDate_Check, + PyTime_Check, + PyDelta_Check, + PyDateTime_IMPORT +) PyDateTime_IMPORT import numpy as np cimport numpy as cnp -from numpy cimport (ndarray, PyArray_Check, PyArray_GETITEM, - PyArray_ITER_DATA, PyArray_ITER_NEXT, PyArray_IterNew, - flatiter, NPY_OBJECT, - int64_t, float32_t, float64_t, - uint8_t, uint64_t, complex128_t) +from numpy cimport ( + NPY_OBJECT, + PyArray_Check, + PyArray_GETITEM, + PyArray_ITER_DATA, + PyArray_ITER_NEXT, + PyArray_IterNew, + complex128_t, + flatiter, + float32_t, + float64_t, + int64_t, + ndarray, + uint8_t, + uint64_t, +) cnp.import_array() cdef extern from "numpy/arrayobject.h": @@ -60,7 +75,12 @@ from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64 from pandas._libs.tslibs.timezones cimport get_timezone, tz_compare from pandas._libs.missing cimport ( - checknull, isnaobj, is_null_datetime64, is_null_timedelta64, is_null_period, C_NA + checknull, + isnaobj, + is_null_datetime64, + is_null_timedelta64, + is_null_period, + C_NA ) @@ -98,14 +118,11 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t: Does not include the actual bytes of the pointers """ - i: Py_ssize_t - n: Py_ssize_t size: int64_t size = 0 - n = len(arr) - for i in range(n): - size += arr[i].__sizeof__() + for value in arr: + size += value.__sizeof__() return size @@ -246,7 +263,7 @@ def item_from_zerodim(val: object) -> object: @cython.wraparound(False) @cython.boundscheck(False) -def fast_unique_multiple(list arrays, sort: bool=True): +def fast_unique_multiple(list arrays, bint sort=True): """ Generate a list of unique values from a list of arrays. @@ -262,21 +279,18 @@ def fast_unique_multiple(list arrays, sort: bool=True): list of unique values """ cdef: - ndarray[object] buf - Py_ssize_t k = len(arrays) - Py_ssize_t i, j, n + ndarray[object] buf_array list uniques = [] dict table = {} - object val, stub = 0 + object value, stub = 0 + + + for buf_array in arrays: + for value in buf_array: + if value not in table: + table[value] = stub + uniques.append(value) - for i in range(k): - buf = arrays[i] - n = len(buf) - for j in range(n): - val = buf[j] - if val not in table: - table[val] = stub - uniques.append(val) if sort is None: try: uniques.sort() @@ -289,7 +303,7 @@ def fast_unique_multiple(list arrays, sort: bool=True): @cython.wraparound(False) @cython.boundscheck(False) -def fast_unique_multiple_list(lists: list, sort: bool=True) -> list: +def fast_unique_multiple_list(lists: list, bint sort=True) -> list: cdef: list buf Py_ssize_t k = len(lists) diff --git a/pandas/_libs/reshape.pyx b/pandas/_libs/reshape.pyx index 4e831081c8e54..6af5caafa5ea8 100644 --- a/pandas/_libs/reshape.pyx +++ b/pandas/_libs/reshape.pyx @@ -1,8 +1,20 @@ import cython from cython import Py_ssize_t -from numpy cimport (int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, - uint32_t, uint64_t, float32_t, float64_t, ndarray) +from numpy cimport ( + float32_t, + float64_t, + int8_t, + int16_t, + int32_t, + int64_t, + ndarray, + uint8_t, + uint16_t, + uint32_t, + uint64_t, +) + cimport numpy as cnp import numpy as np from pandas._libs.lib cimport c_is_list_like @@ -125,8 +137,8 @@ def explode(ndarray[object] values): if c_is_list_like(v, False): if len(v): - for j in range(len(v)): - result[count] = v[j] + for value in v: + result[count] = value count += 1 else: # empty list-like, use a nan marker diff --git a/pandas/_libs/sparse.pyx b/pandas/_libs/sparse.pyx index 3a6dd506b2428..4ca053a0ee83a 100644 --- a/pandas/_libs/sparse.pyx +++ b/pandas/_libs/sparse.pyx @@ -448,7 +448,7 @@ cdef class BlockIndex(SparseIndex): ylen = y.blengths # block may be split, but can't exceed original len / 2 + 1 - max_len = int(min(self.length, y.length) / 2) + 1 + max_len = min(self.length, y.length) // 2 + 1 out_bloc = np.empty(max_len, dtype=np.int32) out_blen = np.empty(max_len, dtype=np.int32) @@ -672,7 +672,7 @@ cdef class BlockUnion(BlockMerge): ystart = self.ystart yend = self.yend - max_len = int(min(self.x.length, self.y.length) / 2) + 1 + max_len = min(self.x.length, self.y.length) // 2 + 1 out_bloc = np.empty(max_len, dtype=np.int32) out_blen = np.empty(max_len, dtype=np.int32) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 9419f0eba39aa..39ff106e235b1 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1,8 +1,6 @@ from datetime import datetime -from cpython.object cimport ( - PyObject_RichCompareBool, - Py_EQ, Py_NE) +from cpython.object cimport PyObject_RichCompareBool, Py_EQ, Py_NE from numpy cimport int64_t, import_array, ndarray import numpy as np @@ -14,15 +12,25 @@ from libc.string cimport strlen, memset import cython -from cpython.datetime cimport (PyDateTime_Check, PyDelta_Check, PyDate_Check, - PyDateTime_IMPORT) +from cpython.datetime cimport ( + PyDate_Check, + PyDateTime_Check, + PyDateTime_IMPORT, + PyDelta_Check, +) # import datetime C API PyDateTime_IMPORT from pandas._libs.tslibs.np_datetime cimport ( - npy_datetimestruct, dtstruct_to_dt64, dt64_to_dtstruct, - pandas_datetime_to_datetimestruct, check_dts_bounds, - NPY_DATETIMEUNIT, NPY_FR_D, NPY_FR_us) + npy_datetimestruct, + dtstruct_to_dt64, + dt64_to_dtstruct, + pandas_datetime_to_datetimestruct, + check_dts_bounds, + NPY_DATETIMEUNIT, + NPY_FR_D, + NPY_FR_us +) cdef extern from "src/datetime/np_datetime.h": int64_t npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT fr, @@ -37,12 +45,15 @@ from pandas._libs.tslibs.timedeltas import Timedelta from pandas._libs.tslibs.timedeltas cimport delta_to_nanoseconds cimport pandas._libs.tslibs.ccalendar as ccalendar -from pandas._libs.tslibs.ccalendar cimport ( - dayofweek, get_day_of_year, is_leapyear) +from pandas._libs.tslibs.ccalendar cimport dayofweek, get_day_of_year, is_leapyear from pandas._libs.tslibs.ccalendar import MONTH_NUMBERS from pandas._libs.tslibs.frequencies cimport ( - get_freq_code, get_base_alias, get_to_timestamp_base, get_freq_str, - get_rule_month) + get_base_alias, + get_freq_code, + get_freq_str, + get_rule_month, + get_to_timestamp_base, +) from pandas._libs.tslibs.parsing import parse_time_string from pandas._libs.tslibs.resolution import Resolution from pandas._libs.tslibs.nattype import nat_strings @@ -55,7 +66,7 @@ from pandas._libs.tslibs.tzconversion cimport tz_convert_utc_to_tzlocal cdef: enum: - INT32_MIN = -2147483648 + INT32_MIN = -2_147_483_648 ctypedef struct asfreq_info: @@ -131,9 +142,7 @@ cdef int64_t get_daytime_conversion_factor(int from_index, int to_index) nogil: int col = max_value(from_index, to_index) # row or col < 6 means frequency strictly lower than Daily, which # do not use daytime_conversion_factors - if row < 6: - return 0 - elif col < 6: + if row < 6 or col < 6: return 0 return daytime_conversion_factor_matrix[row - 6][col - 6] @@ -179,8 +188,7 @@ cdef freq_conv_func get_asfreq_func(int from_freq, int to_freq) nogil: return asfreq_MtoB elif from_group == FR_WK: return asfreq_WtoB - elif from_group in [FR_DAY, FR_HR, FR_MIN, FR_SEC, - FR_MS, FR_US, FR_NS]: + elif from_group in [FR_DAY, FR_HR, FR_MIN, FR_SEC, FR_MS, FR_US, FR_NS]: return asfreq_DTtoB else: return nofunc @@ -289,17 +297,15 @@ cdef int64_t DtoB(npy_datetimestruct *dts, int roll_back, return DtoB_weekday(unix_date) -cdef inline int64_t upsample_daytime(int64_t ordinal, - asfreq_info *af_info) nogil: +cdef inline int64_t upsample_daytime(int64_t ordinal, asfreq_info *af_info) nogil: if (af_info.is_end): return (ordinal + 1) * af_info.intraday_conversion_factor - 1 else: return ordinal * af_info.intraday_conversion_factor -cdef inline int64_t downsample_daytime(int64_t ordinal, - asfreq_info *af_info) nogil: - return ordinal // (af_info.intraday_conversion_factor) +cdef inline int64_t downsample_daytime(int64_t ordinal, asfreq_info *af_info) nogil: + return ordinal // af_info.intraday_conversion_factor cdef inline int64_t transform_via_day(int64_t ordinal, @@ -1463,16 +1469,13 @@ def extract_freq(ndarray[object] values): # TODO: Change type to const object[:] when Cython supports that. cdef: - Py_ssize_t i, n = len(values) - object p - - for i in range(n): - p = values[i] + object value + for value in values: try: # now Timestamp / NaT has freq attr - if is_period_object(p): - return p.freq + if is_period_object(value): + return value.freq except AttributeError: pass diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index 5508b208de00a..396d5ca9ee35d 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -45,8 +45,7 @@ cdef dict _parse_code_table = {'y': 0, 'u': 22} -def array_strptime(object[:] values, object fmt, - bint exact=True, errors='raise'): +def array_strptime(object[:] values, object fmt, bint exact=True, errors='raise'): """ Calculates the datetime structs represented by the passed array of strings @@ -78,12 +77,10 @@ def array_strptime(object[:] values, object fmt, if fmt is not None: if '%W' in fmt or '%U' in fmt: if '%Y' not in fmt and '%y' not in fmt: - raise ValueError("Cannot use '%W' or '%U' without " - "day and year") + raise ValueError("Cannot use '%W' or '%U' without day and year") if ('%A' not in fmt and '%a' not in fmt and '%w' not in fmt): - raise ValueError("Cannot use '%W' or '%U' without " - "day and year") + raise ValueError("Cannot use '%W' or '%U' without day and year") elif '%Z' in fmt and '%z' in fmt: raise ValueError("Cannot parse both %Z and %z") @@ -749,6 +746,6 @@ cdef parse_timezone_directive(str z): microseconds = int(gmtoff_remainder + gmtoff_remainder_padding) total_minutes = ((hours * 60) + minutes + (seconds // 60) + - (microseconds // 60000000)) + (microseconds // 60_000_000)) total_minutes = -total_minutes if z.startswith("-") else total_minutes return pytz.FixedOffset(total_minutes) diff --git a/pandas/_libs/tslibs/timezones.pyx b/pandas/_libs/tslibs/timezones.pyx index 35ee87e714fa8..07947f6677c04 100644 --- a/pandas/_libs/tslibs/timezones.pyx +++ b/pandas/_libs/tslibs/timezones.pyx @@ -196,7 +196,7 @@ cdef int64_t[:] unbox_utcoffsets(object transinfo): arr = np.empty(sz, dtype='i8') for i in range(sz): - arr[i] = int(transinfo[i][0].total_seconds()) * 1000000000 + arr[i] = int(transinfo[i][0].total_seconds()) * 1_000_000_000 return arr @@ -217,7 +217,7 @@ cdef object get_dst_info(object tz): if cache_key is None: # e.g. pytz.FixedOffset, matplotlib.dates._UTC, # psycopg2.tz.FixedOffsetTimezone - num = int(get_utcoffset(tz, None).total_seconds()) * 1000000000 + num = int(get_utcoffset(tz, None).total_seconds()) * 1_000_000_000 return (np.array([NPY_NAT + 1], dtype=np.int64), np.array([num], dtype=np.int64), None) From 8634a370129df78ea0670b07cf385be8c03ba1e4 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 14 Feb 2020 16:05:19 +0200 Subject: [PATCH 2/8] Reverted "bint" REF: https://github.com/pandas-dev/pandas/pull/31808/files#r376721172 --- pandas/_libs/lib.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index c6f4cd0e893ff..cb846055edf25 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -263,7 +263,7 @@ def item_from_zerodim(val: object) -> object: @cython.wraparound(False) @cython.boundscheck(False) -def fast_unique_multiple(list arrays, bint sort=True): +def fast_unique_multiple(list arrays, sort: bool = True): """ Generate a list of unique values from a list of arrays. @@ -303,7 +303,7 @@ def fast_unique_multiple(list arrays, bint sort=True): @cython.wraparound(False) @cython.boundscheck(False) -def fast_unique_multiple_list(lists: list, bint sort=True) -> list: +def fast_unique_multiple_list(lists: list, sort: bool = True) -> list: cdef: list buf Py_ssize_t k = len(lists) From 362e1f728b5b010817ed6f6ffb2b5c7d9b664510 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 14 Feb 2020 16:18:32 +0200 Subject: [PATCH 3/8] Added trailing comma to imports REF: https://github.com/pandas-dev/pandas/pull/31808/files#r378523656 --- pandas/_libs/lib.pyx | 4 ++-- pandas/_libs/tslibs/period.pyx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index cb846055edf25..b012e58af2a92 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -20,7 +20,7 @@ from cpython.datetime cimport ( PyDate_Check, PyTime_Check, PyDelta_Check, - PyDateTime_IMPORT + PyDateTime_IMPORT, ) PyDateTime_IMPORT @@ -80,7 +80,7 @@ from pandas._libs.missing cimport ( is_null_datetime64, is_null_timedelta64, is_null_period, - C_NA + C_NA, ) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 39ff106e235b1..0970b2782e02f 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -29,7 +29,7 @@ from pandas._libs.tslibs.np_datetime cimport ( check_dts_bounds, NPY_DATETIMEUNIT, NPY_FR_D, - NPY_FR_us + NPY_FR_us, ) cdef extern from "src/datetime/np_datetime.h": From e1511839120fdcf0bd3397b1745e51bb92d91166 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 14 Feb 2020 16:32:12 +0200 Subject: [PATCH 4/8] Reverted bad code --- pandas/_libs/lib.pyx | 27 +++++++++++++++++---------- pandas/_libs/reshape.pyx | 4 ++-- pandas/_libs/tslibs/period.pyx | 6 ++++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index b012e58af2a92..7a18429f21a18 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -118,11 +118,14 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t: Does not include the actual bytes of the pointers """ + i: Py_ssize_t + n: Py_ssize_t size: int64_t size = 0 - for value in arr: - size += value.__sizeof__() + n = len(arr) + for i in range(n): + size += arr[i].__sizeof__() return size @@ -279,17 +282,21 @@ def fast_unique_multiple(list arrays, sort: bool = True): list of unique values """ cdef: - ndarray[object] buf_array + ndarray[object] buf + Py_ssize_t k = len(arrays) + Py_ssize_t i, j, n list uniques = [] dict table = {} - object value, stub = 0 - + object val, stub = 0 - for buf_array in arrays: - for value in buf_array: - if value not in table: - table[value] = stub - uniques.append(value) + for i in range(k): + buf = arrays[i] + n = len(buf) + for j in range(n): + val = buf[j] + if val not in table: + table[val] = stub + uniques.append(val) if sort is None: try: diff --git a/pandas/_libs/reshape.pyx b/pandas/_libs/reshape.pyx index 6af5caafa5ea8..e74b5919a4590 100644 --- a/pandas/_libs/reshape.pyx +++ b/pandas/_libs/reshape.pyx @@ -137,8 +137,8 @@ def explode(ndarray[object] values): if c_is_list_like(v, False): if len(v): - for value in v: - result[count] = value + for j in range(len(v)): + result[count] = v[j] count += 1 else: # empty list-like, use a nan marker diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 0970b2782e02f..7d383c54cb7ae 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1469,9 +1469,12 @@ def extract_freq(ndarray[object] values): # TODO: Change type to const object[:] when Cython supports that. cdef: + Py_ssize_t i, n = len(values) object value - for value in values: + for i in range(n): + value = values[i] + try: # now Timestamp / NaT has freq attr if is_period_object(value): @@ -1481,7 +1484,6 @@ def extract_freq(ndarray[object] values): raise ValueError('freq not specified and cannot be inferred') - # ----------------------------------------------------------------------- # period helpers From b369447298dfec91576db6df57ed4b1d27d83ecc Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 15 Feb 2020 10:36:34 +0200 Subject: [PATCH 5/8] Lint issues --- pandas/_libs/tslibs/period.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 7d383c54cb7ae..f63fc39738f64 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1487,6 +1487,7 @@ def extract_freq(ndarray[object] values): # ----------------------------------------------------------------------- # period helpers + @cython.wraparound(False) @cython.boundscheck(False) cdef int64_t[:] localize_dt64arr_to_period(const int64_t[:] stamps, From 208bc03d269125cb5ba99f4cc46a7be41755d4b5 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 15 Feb 2020 12:19:43 +0200 Subject: [PATCH 6/8] Reverted wrong code REF: https://github.com/pandas-dev/pandas/pull/31808#discussion_r379806862 --- pandas/_libs/tslibs/period.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index f63fc39738f64..0287d1c97c458 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -142,7 +142,9 @@ cdef int64_t get_daytime_conversion_factor(int from_index, int to_index) nogil: int col = max_value(from_index, to_index) # row or col < 6 means frequency strictly lower than Daily, which # do not use daytime_conversion_factors - if row < 6 or col < 6: + if row < 6: + return 0 + elif col < 6: return 0 return daytime_conversion_factor_matrix[row - 6][col - 6] From 0b47e28ca088cc8f57b7e711d158530d3539c45c Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 22 Feb 2020 12:25:43 +0200 Subject: [PATCH 7/8] Removed parens REF: https://github.com/pandas-dev/pandas/pull/31808#discussion_r381626183 --- pandas/_libs/tslibs/period.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 0287d1c97c458..c3a47902cff0f 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -300,7 +300,7 @@ cdef int64_t DtoB(npy_datetimestruct *dts, int roll_back, cdef inline int64_t upsample_daytime(int64_t ordinal, asfreq_info *af_info) nogil: - if (af_info.is_end): + if af_info.is_end: return (ordinal + 1) * af_info.intraday_conversion_factor - 1 else: return ordinal * af_info.intraday_conversion_factor From eaf2d49a87ac5fc962b5a82e4484d57c6c8c8ab3 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sat, 22 Feb 2020 12:27:52 +0200 Subject: [PATCH 8/8] "in fmt" in prev line REF: https://github.com/pandas-dev/pandas/pull/31808#discussion_r381626633 --- pandas/_libs/tslibs/strptime.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index 396d5ca9ee35d..dfe050c7bbff7 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -78,8 +78,7 @@ def array_strptime(object[:] values, object fmt, bint exact=True, errors='raise' if '%W' in fmt or '%U' in fmt: if '%Y' not in fmt and '%y' not in fmt: raise ValueError("Cannot use '%W' or '%U' without day and year") - if ('%A' not in fmt and '%a' not in fmt and '%w' not - in fmt): + if '%A' not in fmt and '%a' not in fmt and '%w' not in fmt: raise ValueError("Cannot use '%W' or '%U' without day and year") elif '%Z' in fmt and '%z' in fmt: raise ValueError("Cannot parse both %Z and %z")