Beispiel #1
0
def tell_time_dtype(col_name, arr):
    if not np.issubdtype(arr.dtype, np.datetime64):
        htype = np.typename(np.sctype2char(arr.dtype))  # Human readable type
        # The content is in a datetime format but not in datetime type
        ledger.tell(
            f"columns '{col_name}' looks like a datetime but the type is '{htype}'. "
            f"Consider using:<br>"
            f"<code>df['{col_name}'] = pd.to_datetime(df.{col_name})</code>")
Beispiel #2
0
def main():
    fname = ""
    if len(sys.argv) < 2:
        usage()
        sys.exit(1)
    else:
        fname = sys.argv[1]

    f = ad.file(fname)

    print "File info:"
    print "  %-18s %d" % ("of variables:", f.nvars)
    print "  %-18s %d - %d" % ("time steps:", f.current_step, f.last_step)
    print "  %-18s %d" % ("file size:", f.file_size)
    print "  %-18s %d" % ("bp version:", f.version)
    print ""
    
    for k in sorted(f.var.keys()):
        v = f.var[k]
        print "  %-17s  %-12s  %d*%s" % (np.typename(np.sctype2char(v.dtype)), v.name, v.nsteps, v.dims)
Beispiel #3
0
def main():
    fname = ""
    if len(sys.argv) < 2:
        usage()
        sys.exit(1)
    else:
        fname = sys.argv[1]

    f = ad.file(fname)

    print "File info:"
    print "  %-18s %d" % ("of variables:", f.nvars)
    print "  %-18s %d - %d" % ("time steps:", f.current_step, f.last_step)
    print "  %-18s %d" % ("file size:", f.file_size)
    print "  %-18s %d" % ("bp version:", f.version)
    print ""

    for k in sorted(f.var.keys()):
        v = f.var[k]
        print "  %-17s  %-12s  %d*%s" % (np.typename(np.sctype2char(v.dtype)), v.name, v.nsteps, v.dims)
import numpy as np

typechars = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q',
             'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']
for typechar in typechars:
    print
    typechar, ' : ', np.typename(typechar)
Beispiel #5
0
import numpy as np

typechars = [
    'S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q', 'S', 'U', 'V', 'b',
    'd', 'g', 'f', 'i', 'h', 'l', 'q'
]
for typechar in typechars:
    print
    typechar, ' : ', np.typename(typechar)
Beispiel #6
0
reveal_type(np.nan_to_num(f8))  # E: {float64}
reveal_type(np.nan_to_num(f, copy=True))  # E: Any
reveal_type(np.nan_to_num(
    AR_f8, nan=1.5))  # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.nan_to_num(
    AR_LIKE_f, posinf=9999))  # E: numpy.ndarray[Any, numpy.dtype[Any]]

reveal_type(
    np.real_if_close(AR_f8))  # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(
    np.real_if_close(AR_c16)
)  # E: Union[numpy.ndarray[Any, numpy.dtype[{float64}]], numpy.ndarray[Any, numpy.dtype[{complex128}]]]
reveal_type(
    np.real_if_close(AR_c8)
)  # E: Union[numpy.ndarray[Any, numpy.dtype[{float32}]], numpy.ndarray[Any, numpy.dtype[{complex64}]]]
reveal_type(
    np.real_if_close(AR_LIKE_f))  # E: numpy.ndarray[Any, numpy.dtype[Any]]

reveal_type(np.typename("h"))  # E: Literal['short']
reveal_type(np.typename("B"))  # E: Literal['unsigned char']
reveal_type(np.typename("V"))  # E: Literal['void']
reveal_type(np.typename("S1"))  # E: Literal['character']

reveal_type(np.common_type(AR_i4))  # E: Type[{float64}]
reveal_type(np.common_type(AR_f2))  # E: Type[{float16}]
reveal_type(np.common_type(AR_f2, AR_i4))  # E: Type[{float64}]
reveal_type(np.common_type(AR_f16, AR_i4))  # E: Type[{float128}]
reveal_type(np.common_type(AR_c8, AR_f2))  # E: Type[{complex64}]
reveal_type(np.common_type(AR_f2, AR_c8, AR_i4))  # E: Type[{complex128}]
Beispiel #7
0
import numpy as np
import numpy.typing as npt

DTYPE_i8: np.dtype[np.int64]

np.mintypecode(DTYPE_i8)  # E: incompatible type
np.iscomplexobj(DTYPE_i8)  # E: incompatible type
np.isrealobj(DTYPE_i8)  # E: incompatible type

np.typename(DTYPE_i8)  # E: No overload variant
np.typename("invalid")  # E: No overload variant

np.common_type(np.timedelta64())  # E: incompatible type