zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
U
¬ý°dá1ã@shddlmZddlZddlmZddlZddlZddlZddlZddl    m
Z
m Z m Z ddl Z ddlmZmZddlmZddlmZddlZddlmZdd    lmZdd
lmZe
rÄdd lmZmZd Zd Z dd„Z!dd„Z"e"dddde efddddœdd„ƒZ#d/ddœdd„Z$d0ddddœd d!„Z%d1d"d#œd$d%„Z&d2d"d#œd&d'„Z'd3dd)œd*d+„Z(d4d,dœd-d.„Z)dS)5é)Ú annotationsN©Úwraps)Ú TYPE_CHECKINGÚAnyÚCallable)ÚFilePathÚReadPickleBuffer)Ú get_lzma_file)Úimport_optional_dependency)Úrands)Ú ensure_clean)Úurlopen)Ú    DataFrameÚSeries) z    timed outz Server Hangupz#HTTP Error 503: Service Unavailablez502: Proxy ErrorzHTTP Error 502: internal errorzHTTP Error 502zHTTP Error 503zHTTP Error 403zHTTP Error 400z$Temporary failure in name resolutionzName or service not knownzConnection refusedzcertificate verify)éeéoénéhé6é<cCs(ddl}ddl}t|jjt|jjtj    fS)Nr)
Ú http.clientÚ urllib.errorÚOSErrorÚclientÚ HTTPExceptionÚ TimeoutErrorÚerrorÚURLErrorÚsocketÚtimeout)ÚhttpÚurllib©r#úJd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/_testing/_io.pyÚ_get_default_network_errorsIsûr%cstˆƒ‡fdd„ƒ}|S)aB
    allows a decorator to take optional positional and keyword arguments.
    Assumes that taking a single, callable, positional argument means that
    it is decorating a function, i.e. something like this::
 
        @my_decorator
        def function(): pass
 
    Calls decorator with decorator(f, *args, **kwargs)
    csN‡‡‡fdd„}ˆ o,tˆƒdko,tˆdƒ}|rFˆd}d‰||ƒS|SdS)Ncsˆ|fˆžˆŽS©Nr#)Úf)ÚargsÚ    decoratorÚkwargsr#r$Údecfsz+optional_args.<locals>.wrapper.<locals>.decérr#)ÚlenÚcallable)r(r*r+Z is_decoratingr'©r))r(r*r$Úwrapperdszoptional_args.<locals>.wrapperr)r)r0r#r/r$Ú optional_argsXs  r1zhttps://www.google.comFÚstrÚbool)ÚurlÚraise_on_errorÚcheck_before_testc    sBddl‰ˆdkrtƒ‰dˆ_tˆƒ‡‡‡‡‡‡‡‡fdd„ƒ}|S)a‘
    Label a test as requiring network connection and, if an error is
    encountered, only raise if it does not find a network connection.
 
    In comparison to ``network``, this assumes an added contract to your test:
    you must assert that, under normal conditions, your test will ONLY fail if
    it does not have network connectivity.
 
    You can call this in 3 ways: as a standard decorator, with keyword
    arguments, or with a positional argument that is the url to check.
 
    Parameters
    ----------
    t : callable
        The test requiring network connectivity.
    url : path
        The url to test via ``pandas.io.common.urlopen`` to check
        for connectivity. Defaults to 'https://www.google.com'.
    raise_on_error : bool
        If True, never catches errors.
    check_before_test : bool
        If True, checks connectivity before running the test case.
    error_classes : tuple or Exception
        error classes to ignore. If not in ``error_classes``, raises the error.
        defaults to OSError. Be careful about changing the error classes here.
    skip_errnos : iterable of int
        Any exception that has .errno or .reason.erno set to one
        of these values will be skipped with an appropriate
        message.
    _skip_on_messages: iterable of string
        any exception e for which one of the strings is
        a substring of str(e) will be skipped with an appropriate
        message. Intended to suppress errors where an errno isn't available.
 
    Notes
    -----
    * ``raise_on_error`` supersedes ``check_before_test``
 
    Returns
    -------
    t : callable
        The decorated test ``t``, with checks for connectivity errors.
 
    Example
    -------
 
    Tests decorated with @network will fail if it's possible to make a network
    connection to another URL (defaults to google.com)::
 
      >>> from pandas import _testing as tm
      >>> @tm.network
      ... def test_network():
      ...     with pd.io.common.urlopen("rabbit://bonanza.com"):
      ...         pass
      >>> test_network()  # doctest: +SKIP
      Traceback
         ...
      URLError: <urlopen error unknown url type: rabbit>
 
      You can specify alternative URLs::
 
        >>> @tm.network("https://www.yahoo.com")
        ... def test_something_with_yahoo():
        ...    raise OSError("Failure Message")
        >>> test_something_with_yahoo()  # doctest: +SKIP
        Traceback (most recent call last):
            ...
        OSError: Failure Message
 
    If you set check_before_test, it will check the url first and not run the
    test on failure::
 
        >>> @tm.network("failing://url.blaher", check_before_test=True)
        ... def test_something():
        ...     print("I ran!")
        ...     raise ValueError("Failure")
        >>> test_something()  # doctest: +SKIP
        Traceback (most recent call last):
            ...
 
    Errors not related to networking will always be raised.
    rNTc
säˆr"ˆs"tˆˆƒs"ˆ dˆ›¡z ˆ||ŽWStk
rÞ}z’t|ddƒ}|sht|dƒrht|jddƒ}|ˆkr€ˆ d|›¡t|ƒ‰t‡fdd„ˆDƒƒr®ˆ d|›¡t|ˆƒr¼ˆr¾‚ˆ d|›¡W5d}~XYnXdS)    Nz<May not have network connectivity because cannot connect to ÚerrnoÚreasonz+Skipping test due to known errno and error c3s|]}| ¡ˆ ¡kVqdSr&)Úlower)Ú.0Úm©Ze_strr#r$Ú    <genexpr>ïsz+network.<locals>.wrapper.<locals>.<genexpr>z;Skipping test because exception message is known and error z4Skipping test due to lack of connectivity and error )    Ú can_connectÚskipÚ    ExceptionÚgetattrÚhasattrr8r2ÚanyÚ
isinstance)r(r*Úerrr7©Ú_skip_on_messagesr6Ú error_classesÚpytestr5Ú skip_errnosÚtr4r<r$r0Øs2ÿþýÿ  ÿznetwork.<locals>.wrapper)rIr%Únetworkr)rKr4r5r6rHrJrGr0r#rFr$rLus\rL)Úreturnc    Csd|dkrtƒ}z6t|dd }|jdkr8W5QR£WdSW5QRXWn|k
rZYdSXdSdS)a@
    Try to connect to the given url. True if succeeds, False if OSError
    raised
 
    Parameters
    ----------
    url : basestring
        The URL to try to connect to
 
    Returns
    -------
    connectable : bool
        Return True if no OSError (unable to connect) or URLError (bad url) was
        raised
    Né)r éÈFT)r%rÚstatus)r4rHÚresponser#r#r$r>ûs
r>rz"FilePath | ReadPickleBuffer | NonezDataFrame | Series)ÚobjÚpathrMc
CsR|}|dkrdtdƒ›d}t|ƒ$}t ||¡t |¡W5QR£SQRXdS)a
    Pickle an object and then read it again.
 
    Parameters
    ----------
    obj : any object
        The object to pickle and then re-read.
    path : str, path object or file-like object, default None
        The path where the pickled object is written and then read.
 
    Returns
    -------
    pandas object
        The original object that was pickled and then re-read.
    NÚ__é
z    __.pickle)r r ÚpdZ    to_pickleZ read_pickle)rRrSÚ_pathZ    temp_pathr#r#r$Úround_trip_pickles 
 rXz
str | None)rSc    CsPddl}| d¡j}|dkr d}t|ƒ}|||ƒƒ|||ƒƒ}W5QRX|S)aÛ
    Write an object to file specified by a pathlib.Path and read it back
 
    Parameters
    ----------
    writer : callable bound to pandas object
        IO writing function (e.g. DataFrame.to_csv )
    reader : callable
        IO reading function (e.g. pd.read_csv )
    path : str, default None
        The path where the object is written and then read.
 
    Returns
    -------
    pandas object
        The original object that was serialized and then re-read.
    rNÚpathlibZ ___pathlib___)rIÚ importorskipÚPathr )ÚwriterÚreaderrSrIr[rRr#r#r$Úround_trip_pathlib7s 
 r^c    CsPddl}| d¡j}|dkr d}t|ƒ}|||ƒƒ|||ƒƒ}W5QRX|S)aá
    Write an object to file specified by a py.path LocalPath and read it back.
 
    Parameters
    ----------
    writer : callable bound to pandas object
        IO writing function (e.g. DataFrame.to_csv )
    reader : callable
        IO reading function (e.g. pd.read_csv )
    path : str, default None
        The path where the object is written and then read.
 
    Returns
    -------
    pandas object
        The original object that was serialized and then re-read.
    rNzpy.pathZ___localpath___)rIrZÚlocalr )r\r]rSrIZ    LocalPathrRr#r#r$Úround_trip_localpathTs 
 r`Útest)Údestc     Csê|f}d}d}|dkr.tj}d}||f}d}n’|dkrntj}d}tj|d}t |¡}    t|ƒ|_||    f}d}nR|d    kr~t    j
}nB|d
krŽt j }n2|d kr¢t d ƒj}n|d kr²tƒ}ntd|›ƒ‚|||d}
t|
|ƒ|ŽW5QRXdS)a¦
    Write data to a compressed file.
 
    Parameters
    ----------
    compression : {'gzip', 'bz2', 'zip', 'xz', 'zstd'}
        The compression type to use.
    path : str
        The file path to write the data.
    data : str
        The data to write.
    dest : str, default "test"
        The destination file (for ZIP only)
 
    Raises
    ------
    ValueError : An invalid compression value was passed in.
    ÚwbÚwriteÚzipÚwÚwritestrÚtar)ÚnameÚaddfileÚgzipÚbz2ZzstdZ    zstandardÚxzzUnrecognized compression type: )ÚmodeN)ÚzipfileÚZipFileÚtarfileÚTarFileÚTarInfoÚioÚBytesIOr-ÚsizerkÚGzipFilerlÚBZ2Filer Úopenr
Ú
ValueErrorrA) Ú compressionrSÚdatarbr(rnÚmethodZcompress_methodÚfileÚbytesr'r#r#r$Úwrite_to_compressedqs6 
 
 r€ÚNonecCs:ddlm}m}|dkr.|ƒD] }||ƒqn||ƒdS)Nr)ÚcloseÚ get_fignums)Zmatplotlib.pyplotr‚rƒ)ZfignumÚ_closerƒr#r#r$r‚©s
 
 r‚)N)N)N)N)ra)N)*Ú
__future__rrlÚ    functoolsrrkrtrrqÚtypingrrrroZpandas._typingrr    Z pandas.compatr
Zpandas.compat._optionalr ZpandasrVZpandas._testing._randomr Zpandas._testing.contextsr Zpandas.io.commonrrrZ_network_error_messagesZ_network_errno_valsr%r1rLr>rXr^r`r€r‚r#r#r#r$Ú<module>sJ       ù#ÿ8