Skip to content

CLN: Remove useless Validation functions #41936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ cdef class Validator:
if not self.is_valid(values[i]):
return False

return self.finalize_validate()
return True

@cython.wraparound(False)
@cython.boundscheck(False)
Expand All @@ -1712,7 +1712,7 @@ cdef class Validator:
if not self.is_valid_skipna(values[i]):
return False

return self.finalize_validate_skipna()
return True

cdef bint is_valid(self, object value) except -1:
return self.is_value_typed(value)
Expand All @@ -1730,18 +1730,6 @@ cdef class Validator:
cdef bint is_array_typed(self) except -1:
return False

cdef inline bint finalize_validate(self):
return True

cdef bint finalize_validate_skipna(self):
"""
If we _only_ saw non-dtype-specific NA values, even if they are valid
for this dtype, we do not infer this dtype.
"""
# TODO(phillipc): Remove the existing validate methods and replace them
# with the skipna versions upon full deprecation of skipna=False
return True


@cython.internal
cdef class BoolValidator(Validator):
Expand Down Expand Up @@ -1893,14 +1881,14 @@ cdef bint is_bytes_array(ndarray values, bint skipna=False):
@cython.internal
cdef class TemporalValidator(Validator):
cdef:
Py_ssize_t generic_null_count
bint all_generic_na

def __cinit__(self, Py_ssize_t n, dtype dtype=np.dtype(np.object_),
bint skipna=False):
self.n = n
self.dtype = dtype
self.skipna = skipna
self.generic_null_count = 0
self.all_generic_na = True

cdef inline bint is_valid(self, object value) except -1:
return self.is_value_typed(value) or self.is_valid_null(value)
Expand All @@ -1913,15 +1901,16 @@ cdef class TemporalValidator(Validator):
cdef:
bint is_typed_null = self.is_valid_null(value)
bint is_generic_null = value is None or util.is_nan(value)
self.generic_null_count += is_typed_null and is_generic_null
if not is_generic_null:
self.all_generic_na = False
return self.is_value_typed(value) or is_typed_null or is_generic_null

cdef inline bint finalize_validate_skipna(self):
cdef bint _validate_skipna(self, ndarray values) except -1:
"""
If we _only_ saw non-dtype-specific NA values, even if they are valid
for this dtype, we do not infer this dtype.
"""
return self.generic_null_count != self.n
return Validator._validate_skipna(self, values) and not self.all_generic_na


@cython.internal
Expand Down