@@ -1644,6 +1644,7 @@ cdef inline bint is_timedelta(object o):
1644
1644
return PyDelta_Check(o) or util.is_timedelta64_object(o)
1645
1645
1646
1646
1647
+ @cython.internal
1647
1648
cdef class Validator:
1648
1649
1649
1650
cdef:
@@ -1662,6 +1663,7 @@ cdef class Validator:
1662
1663
return False
1663
1664
1664
1665
if self .is_array_typed():
1666
+ # i.e. this ndarray is already of the desired dtype
1665
1667
return True
1666
1668
elif self .dtype.type_num == NPY_OBJECT:
1667
1669
if self .skipna:
@@ -1717,11 +1719,16 @@ cdef class Validator:
1717
1719
return True
1718
1720
1719
1721
cdef bint finalize_validate_skipna(self ):
1722
+ """
1723
+ If we _only_ saw non-dtype-specific NA values, even if they are valid
1724
+ for this dtype, we do not infer this dtype.
1725
+ """
1720
1726
# TODO(phillipc): Remove the existing validate methods and replace them
1721
1727
# with the skipna versions upon full deprecation of skipna=False
1722
1728
return True
1723
1729
1724
1730
1731
+ @cython.internal
1725
1732
cdef class BoolValidator(Validator):
1726
1733
cdef inline bint is_value_typed(self , object value) except - 1 :
1727
1734
return util.is_bool_object(value)
@@ -1738,6 +1745,7 @@ cpdef bint is_bool_array(ndarray values, bint skipna=False):
1738
1745
return validator.validate(values)
1739
1746
1740
1747
1748
+ @cython.internal
1741
1749
cdef class IntegerValidator(Validator):
1742
1750
cdef inline bint is_value_typed(self , object value) except - 1 :
1743
1751
return util.is_integer_object(value)
@@ -1746,13 +1754,15 @@ cdef class IntegerValidator(Validator):
1746
1754
return issubclass (self .dtype.type, np.integer)
1747
1755
1748
1756
1757
+ # Note: only python-exposed for tests
1749
1758
cpdef bint is_integer_array(ndarray values):
1750
1759
cdef:
1751
1760
IntegerValidator validator = IntegerValidator(len (values),
1752
1761
values.dtype)
1753
1762
return validator.validate(values)
1754
1763
1755
1764
1765
+ @cython.internal
1756
1766
cdef class IntegerNaValidator(Validator):
1757
1767
cdef inline bint is_value_typed(self , object value) except - 1 :
1758
1768
return (util.is_integer_object(value)
@@ -1766,6 +1776,7 @@ cdef bint is_integer_na_array(ndarray values):
1766
1776
return validator.validate(values)
1767
1777
1768
1778
1779
+ @cython.internal
1769
1780
cdef class IntegerFloatValidator(Validator):
1770
1781
cdef inline bint is_value_typed(self , object value) except - 1 :
1771
1782
return util.is_integer_object(value) or util.is_float_object(value)
@@ -1781,6 +1792,7 @@ cdef bint is_integer_float_array(ndarray values):
1781
1792
return validator.validate(values)
1782
1793
1783
1794
1795
+ @cython.internal
1784
1796
cdef class FloatValidator(Validator):
1785
1797
cdef inline bint is_value_typed(self , object value) except - 1 :
1786
1798
return util.is_float_object(value)
@@ -1789,12 +1801,14 @@ cdef class FloatValidator(Validator):
1789
1801
return issubclass (self .dtype.type, np.floating)
1790
1802
1791
1803
1804
+ # Note: only python-exposed for tests
1792
1805
cpdef bint is_float_array(ndarray values):
1793
1806
cdef:
1794
1807
FloatValidator validator = FloatValidator(len (values), values.dtype)
1795
1808
return validator.validate(values)
1796
1809
1797
1810
1811
+ @cython.internal
1798
1812
cdef class ComplexValidator(Validator):
1799
1813
cdef inline bint is_value_typed(self , object value) except - 1 :
1800
1814
return (
@@ -1812,6 +1826,7 @@ cdef bint is_complex_array(ndarray values):
1812
1826
return validator.validate(values)
1813
1827
1814
1828
1829
+ @cython.internal
1815
1830
cdef class DecimalValidator(Validator):
1816
1831
cdef inline bint is_value_typed(self , object value) except - 1 :
1817
1832
return is_decimal(value)
@@ -1823,6 +1838,7 @@ cdef bint is_decimal_array(ndarray values):
1823
1838
return validator.validate(values)
1824
1839
1825
1840
1841
+ @cython.internal
1826
1842
cdef class StringValidator(Validator):
1827
1843
cdef inline bint is_value_typed(self , object value) except - 1 :
1828
1844
return isinstance (value, str )
@@ -1843,6 +1859,7 @@ cpdef bint is_string_array(ndarray values, bint skipna=False):
1843
1859
return validator.validate(values)
1844
1860
1845
1861
1862
+ @cython.internal
1846
1863
cdef class BytesValidator(Validator):
1847
1864
cdef inline bint is_value_typed(self , object value) except - 1 :
1848
1865
return isinstance (value, bytes)
@@ -1858,6 +1875,7 @@ cdef bint is_bytes_array(ndarray values, bint skipna=False):
1858
1875
return validator.validate(values)
1859
1876
1860
1877
1878
+ @cython.internal
1861
1879
cdef class TemporalValidator(Validator):
1862
1880
cdef:
1863
1881
Py_ssize_t generic_null_count
@@ -1884,9 +1902,14 @@ cdef class TemporalValidator(Validator):
1884
1902
return self .is_value_typed(value) or is_typed_null or is_generic_null
1885
1903
1886
1904
cdef inline bint finalize_validate_skipna(self ):
1905
+ """
1906
+ If we _only_ saw non-dtype-specific NA values, even if they are valid
1907
+ for this dtype, we do not infer this dtype.
1908
+ """
1887
1909
return self .generic_null_count != self .n
1888
1910
1889
1911
1912
+ @cython.internal
1890
1913
cdef class DatetimeValidator(TemporalValidator):
1891
1914
cdef bint is_value_typed(self , object value) except - 1 :
1892
1915
return PyDateTime_Check(value)
@@ -1902,19 +1925,21 @@ cpdef bint is_datetime_array(ndarray values, bint skipna=True):
1902
1925
return validator.validate(values)
1903
1926
1904
1927
1928
+ @cython.internal
1905
1929
cdef class Datetime64Validator(DatetimeValidator):
1906
1930
cdef inline bint is_value_typed(self , object value) except - 1 :
1907
1931
return util.is_datetime64_object(value)
1908
1932
1909
1933
1934
+ # Note: only python-exposed for tests
1910
1935
cpdef bint is_datetime64_array(ndarray values):
1911
1936
cdef:
1912
1937
Datetime64Validator validator = Datetime64Validator(len (values),
1913
1938
skipna = True )
1914
1939
return validator.validate(values)
1915
1940
1916
1941
1917
- # TODO : only non-here use is in test
1942
+ # Note : only python-exposed for tests
1918
1943
def is_datetime_with_singletz_array (values: ndarray ) -> bool:
1919
1944
"""
1920
1945
Check values have the same tzinfo attribute.
@@ -1945,6 +1970,7 @@ def is_datetime_with_singletz_array(values: ndarray) -> bool:
1945
1970
return True
1946
1971
1947
1972
1973
+ @cython.internal
1948
1974
cdef class TimedeltaValidator(TemporalValidator):
1949
1975
cdef bint is_value_typed(self , object value) except - 1 :
1950
1976
return PyDelta_Check(value)
@@ -1953,12 +1979,13 @@ cdef class TimedeltaValidator(TemporalValidator):
1953
1979
return is_null_timedelta64(value)
1954
1980
1955
1981
1982
+ @cython.internal
1956
1983
cdef class AnyTimedeltaValidator(TimedeltaValidator):
1957
1984
cdef inline bint is_value_typed(self , object value) except - 1 :
1958
1985
return is_timedelta(value)
1959
1986
1960
1987
1961
- # TODO : only non-here use is in test
1988
+ # Note : only python-exposed for tests
1962
1989
cpdef bint is_timedelta_or_timedelta64_array(ndarray values):
1963
1990
"""
1964
1991
Infer with timedeltas and/or nat/none.
@@ -1969,22 +1996,26 @@ cpdef bint is_timedelta_or_timedelta64_array(ndarray values):
1969
1996
return validator.validate(values)
1970
1997
1971
1998
1999
+ @cython.internal
1972
2000
cdef class DateValidator(Validator):
1973
2001
cdef inline bint is_value_typed(self , object value) except - 1 :
1974
2002
return PyDate_Check(value)
1975
2003
1976
2004
2005
+ # Note: only python-exposed for tests
1977
2006
cpdef bint is_date_array(ndarray values, bint skipna = False ):
1978
2007
cdef:
1979
2008
DateValidator validator = DateValidator(len (values), skipna = skipna)
1980
2009
return validator.validate(values)
1981
2010
1982
2011
2012
+ @cython.internal
1983
2013
cdef class TimeValidator(Validator):
1984
2014
cdef inline bint is_value_typed(self , object value) except - 1 :
1985
2015
return PyTime_Check(value)
1986
2016
1987
2017
2018
+ # Note: only python-exposed for tests
1988
2019
cpdef bint is_time_array(ndarray values, bint skipna = False ):
1989
2020
cdef:
1990
2021
TimeValidator validator = TimeValidator(len (values), skipna = skipna)
@@ -2022,6 +2053,7 @@ cdef bint is_period_array(ndarray[object] values):
2022
2053
return True
2023
2054
2024
2055
2056
+ # Note: only python-exposed for tests
2025
2057
cpdef bint is_interval_array(ndarray values):
2026
2058
"""
2027
2059
Is this an ndarray of Interval (or np.nan) with a single dtype?
0 commit comments