You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DTYPE_OBJECTABLE_DT64_UNITS=frozenset((
'D', 'h', 'm', 's', 'ms', 'us',
))
defis_objectable_dt64(array: TNDArrayAny) ->bool:
'''This function assumes a dt64 array. '''unit=np.datetime_data(array.dtype)[0]
ifunitnotinDTYPE_OBJECTABLE_DT64_UNITS: # year, month, nanosecond, etc.returnFalse# for all dt64 units that can be converted to object, we need to determine if the can fit in the more narrow range of Python datetime types.years=array[~np.isnat(array)].astype(DT64_YEAR).astype(DTYPE_INT_DEFAULT) +1970ifnp.any(years<datetime.MINYEAR):
returnFalseifnp.any(years>datetime.MAXYEAR):
returnFalsereturnTruedefis_objectable(array: TNDArrayAny) ->bool:
'''If an array is dt64 array, evaluate if it can go to Python object without resolution loss or other distortions (coercion to integer). '''ifarray.dtype.kindinDTYPE_NAT_KINDS:
returnis_objectable_dt64(array)
returnTruedefastype_array(array: TNDArrayAny, dtype: TDtypeAny|None) ->TNDArrayAny:
'''This function handles NumPy types that cannot be converted to Python objects without loss of representation, namely some dt64 units. NOTE: this does not set the returned array to be immutable. '''dt=np.dtype(None) ifdtypeisNoneelsedtypedt_equal=array.dtype==dtifdt==DTYPE_OBJECTandnotdt_equalandarray.dtype.kindinDTYPE_NAT_KINDS:
ifnotis_objectable_dt64(array):
# NOTE: this can be faster implemented in Cpost=np.empty(array.shape, dtype=dt)
foriloc, vinnp.ndenumerate(array):
post[iloc] =vreturnpostifdt_equalandarray.flags.writeableisFalse:
# if dtypes match and array is immutable can return same instancereturnarrayreturnarray.astype(dt)
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: