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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
U
¬ý°dwFã@s˜ddlmZddlmZmZddlmZddlZddlm    Z
ddl m Z m Z mZmZmZddlmZmZmZddlmZmZdd    lmZdd
lmZdd lmZdd lmZdd l m!Z!m"Z"m#Z#m$Z$ddl%m&m'Z(ddl)m&m*m+Z,ddl)m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3m4Z4e5e,j6ƒZ6e6 7ddi¡ddiZ8dd„Z9e4dddge!j:e!dde4ddge!ƒGdd „d e/ƒƒƒZ;d%d!d d"œd#d$„Z<dS)&é)Ú annotations)ÚdatetimeÚ    timedelta)ÚHashableN)Úindex)Ú
BaseOffsetÚNaTÚPeriodÚ
ResolutionÚTick)ÚDtypeÚDtypeObjÚnpt)Úcache_readonlyÚdoc)Ú
is_integer)Ú PeriodDtype)Ú    ABCSeries)Úis_valid_na_for_dtype)Ú PeriodArrayÚ period_arrayÚraise_on_incompatibleÚvalidate_dtype_freq)Úmaybe_extract_name)ÚDatetimeIndexOpsMixin)Ú DatetimeIndexÚIndex)Ú inherit_namesZ target_klasszPeriodIndex or list of PeriodsÚklassrcKsJ| d¡}|jdkr:| dd¡}t||d}|j|f|ŽS||f|ŽSdS)NÚdataÚint64Úfreq©r!)ÚpopÚdtyperÚ _simple_new)ÚclsÚdÚvaluesr!©r)úQd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/indexes/period.pyÚ_new_PeriodIndex;s 
 
  r+ÚstrftimeÚ
start_timeZend_timeT)ÚwrapZ is_leap_yearZ_format_native_typescsøeZdZUdZdZded<ded<ded<eZd    Ze    d
d œd d „ƒZ
e dd œdd„ƒZ e ejfdddœe—ŽdUdddœdd„ƒZe ejƒdVdddœdd„ƒZe    e ejjƒdd œdd„ƒƒZe    e ejjƒdd œd d!„ƒƒZe    e ejjƒdd œd"d#„ƒƒZdWd%d&d'dd(œd)d*„Ze    d+d œd,d-„ƒZd.d œd/d0„Zd1d&d2œd3d4„Zdd5d+d6œ‡fd7d8„ Ze    d&d œd9d:„ƒZe    dd œd;d<„ƒZ‡fd=d>„Zd?d@„ZdAdBdCœdDdE„ZdFdAdGœdHdI„Ze e j!ƒddJœ‡fdKdL„ ƒZ!ddFdMœdNdO„Z"e e j#ƒdXdQdRœdSdT„ƒZ#‡Z$S)YÚ PeriodIndexa–
    Immutable ndarray holding ordinal values indicating regular periods in time.
 
    Index keys are boxed to Period objects which carries the metadata (eg,
    frequency information).
 
    Parameters
    ----------
    data : array-like (1d int np.ndarray or PeriodArray), optional
        Optional period-like data to construct index with.
    copy : bool
        Make a copy of input ndarray.
    freq : str or period object, optional
        One of pandas period strings or corresponding objects.
    year : int, array, or Series, default None
    month : int, array, or Series, default None
    quarter : int, array, or Series, default None
    day : int, array, or Series, default None
    hour : int, array, or Series, default None
    minute : int, array, or Series, default None
    second : int, array, or Series, default None
    dtype : str or PeriodDtype, default None
 
    Attributes
    ----------
    day
    dayofweek
    day_of_week
    dayofyear
    day_of_year
    days_in_month
    daysinmonth
    end_time
    freq
    freqstr
    hour
    is_leap_year
    minute
    month
    quarter
    qyear
    second
    start_time
    week
    weekday
    weekofyear
    year
 
    Methods
    -------
    asfreq
    strftime
    to_timestamp
 
    See Also
    --------
    Index : The base pandas Index type.
    Period : Represents a period of time.
    DatetimeIndex : Index with datetime64 data.
    TimedeltaIndex : Index of timedelta64 data.
    period_range : Create a fixed-frequency PeriodIndex.
 
    Examples
    --------
    >>> idx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3])
    >>> idx
    PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
    Z periodindexrÚ_datarr!rr$Tztype[libindex.PeriodEngine])ÚreturncCstjS©N)ÚlibindexZ PeriodEngine©Úselfr)r)r*Ú _engine_type›szPeriodIndex._engine_typer
cCs|jjSr2)r$Ú_resolution_objr4r)r)r*r7ŸszPeriodIndex._resolution_objzpandas.arrays.PeriodArray)ÚotherZ
other_nameNÚEÚstr)Úhowr1cCs"|j ||¡}t|ƒj||jdS©N©Úname)r0ÚasfreqÚtyper%r>©r5r!r;Zarrr)r)r*r?¨szPeriodIndex.asfreqÚstartrcCs|j ||¡}tj||jdSr<)r0Ú to_timestamprr%r>rAr)r)r*rC²szPeriodIndex.to_timestamprcCst|jj|jdSr<)rr0Úhourr>r4r)r)r*rD·szPeriodIndex.hourcCst|jj|jdSr<)rr0Úminuter>r4r)r)r*rE¼szPeriodIndex.minutecCst|jj|jdSr<)rr0Úsecondr>r4r)r)r*rFÁszPeriodIndex.secondFz Dtype | NoneÚboolr)r$Úcopyr>r1c Ks8dddddddh}d}    |s.t|ttfƒr.|j}    t|ƒ |¡s^tt|ƒ|ƒd}
td    |
›ƒ‚t|||ƒ}|dkr°|dkr°|sˆ|     d¡t
  ddd||¡\}} | }t
||d
}njt ||ƒ}|rÜt||ƒrÜ|j |krÜ| |¡}|dkr|dk    rtj|tjd }t
||d
}n t||d }|r(| ¡}|j|||    d S)NÚyearÚmonthÚdayZquarterrDrErFrz-__new__() got an unexpected keyword argument r"©r$)rr!)r>Úrefs)Ú
isinstancerrZ _referencesÚsetÚissubsetÚlistÚ    TypeErrorrZ_raise_scalar_data_errorrÚ_generate_rangerr!r?ÚnpÚasarrayr rrHr%) r&rZordinalr!r$rHr>ÚfieldsZvalid_field_setrMZargumentZfreq2r)r)r*Ú__new__És> ù
 
 
 
 zPeriodIndex.__new__z
np.ndarraycCstj|tdS)NrL)rTrUÚobjectr4r)r)r*r(szPeriodIndex.valueszint | npt.NDArray[np.int64]cCsxt|ttjttjfƒr4t|jtƒrj|j |¡}|Sn6t|t    ƒr^|j
|jj
krR|j St ||ƒ‚n t |ƒrj|St |dƒ‚dS)aÅ
        Convert timedelta-like input to an integer multiple of self.freq
 
        Parameters
        ----------
        other : timedelta, np.timedelta64, DateOffset, int, np.ndarray
 
        Returns
        -------
        converted : int, np.ndarray[int64]
 
        Raises
        ------
        IncompatibleFrequency : if the input cannot be written as a multiple
            of self.freq.  Note IncompatibleFrequency subclasses ValueError.
        N)rNrrTZ timedelta64r Zndarrayr!r0Z _check_timedeltalike_freq_compatrÚbaseÚnrr)r5r8Údeltar)r)r*Ú_maybe_convert_timedeltas  
 z$PeriodIndex._maybe_convert_timedeltar )r$r1cCs2t|tƒsdS|j}|j}|j|jko0|j|jkS)zF
        Can we compare values of the given dtype to our own?
        F)rNrr!Ú_period_dtype_coderZ)r5r$r!Zown_freqr)r)r*Ú_is_comparable_dtype6s
þ
üz PeriodIndex._is_comparable_dtypeznpt.NDArray[np.bool_])ÚwhereÚmaskr1cs<t|tƒrt|j|jd}nt|tƒs.tdƒ‚tƒ ||¡S)z
        where : array of timestamps
        mask : np.ndarray[bool]
            Array of booleans where data is not NA.
        r"z6asof_locs `where` must be DatetimeIndex or PeriodIndex)rNrr/Z_valuesr!rRÚsuperÚ    asof_locs)r5r_r`©Ú    __class__r)r*rbLs
 
 
zPeriodIndex.asof_locscCsHt|ƒdkrdS|jstdƒ‚|j}t|dd…|dd…dk ¡ƒS)z‰
        Returns True if this PeriodIndex is range-like in that all Periods
        between start and end are present, in order.
        rTzIndex is not monotonicéNéÿÿÿÿé)ÚlenZis_monotonic_increasingÚ
ValueErrorZasi8rGÚall)r5r(r)r)r*Úis_fullYs  zPeriodIndex.is_fullcCsdS)NÚperiodr)r4r)r)r*Ú inferred_typefszPeriodIndex.inferred_typecs(tƒ ||¡}|j|jkr$| |¡}|Sr2)raÚ_convert_tolerancer$r\)r5Z    toleranceÚtargetrcr)r*rnos 
zPeriodIndex._convert_tolerancec
CsP|}| |¡t||jƒr t}nît|tƒrØz| |¡\}}Wn4tk
rp}ztd|›dƒ|‚W5d}~XYnX|     |¡r¸z| 
||¡WStk
r¶}zt|ƒ|‚W5d}~XYnX||j krÎ|  |¡}nt|ƒ‚n6t|t ƒrî| |¡n t|tƒr|  |¡}nt|ƒ‚zt ||¡WStk
rJ}zt|ƒ|‚W5d}~XYnXdS)a»
        Get integer location for requested label.
 
        Parameters
        ----------
        key : Period, NaT, str, or datetime
            String or datetime key must be parsable as Period.
 
        Returns
        -------
        loc : int or ndarray[int64]
 
        Raises
        ------
        KeyError
            Key is not present in the index.
        TypeError
            If key is listlike or otherwise not hashable.
        zCannot interpret 'z ' as periodN)Z_check_indexing_errorrr$rrNr:Z_parse_with_resoriÚKeyErrorZ_can_partial_date_sliceZ_partial_date_slicer7Ú_cast_partial_indexing_scalarr    Ú_disallow_mismatched_indexingrrÚget_loc)r5ÚkeyZorig_keyÚparsedÚresoÚerrr)r)r*rs|s4
 
$
 
 
 
   zPeriodIndex.get_locr    ÚNone)rtr1cCs0|j}|j}|j|jkr$|j|jks,t|ƒ‚dSr2)r!rZr]rp)r5rtZsfreqZkfreqr)r)r*rrºs
ÿþý
z)PeriodIndex._disallow_mismatched_indexingr)Úlabelr1c
CsDzt||jd}Wn,tk
r>}zt|ƒ|‚W5d}~XYnX|S)Nr")r    r!rirp)r5ryrlrwr)r)r*rqÉs
z)PeriodIndex._cast_partial_indexing_scalar)Úsidecs"t|tƒr| |¡}tƒ ||¡Sr2)rNrrqraÚ_maybe_cast_slice_bound)r5ryrzrcr)r*r{Ñs
 
z#PeriodIndex._maybe_cast_slice_bound)rvrucCs.t||jd}|j|jdd|j|jddfS)Nr"rB)r;Úend)r    Z attr_abbrevr?r!)r5rvruZivr)r)r*Ú_parsed_string_to_boundsØsz$PeriodIndex._parsed_string_to_boundsreÚint)ÚperiodscCs&|dk    rtdt|ƒj›dƒ‚||S)Nz%`freq` argument is not supported for z.shift)rRr@Ú__name__)r5rr!r)r)r*ÚshiftÜs
ÿzPeriodIndex.shift)Nr9)NrB)NNNNFN)reN)%r€Ú
__module__Ú __qualname__Ú__doc__Z_typÚ__annotations__rZ    _data_clsZ!_supports_partial_string_indexingÚpropertyr6rr7rr?Ú_shared_doc_kwargsrCrDÚfgetrErFrWr(r\r^rbrkrmrnrsrrrqrr{r}rÚ __classcell__r)r)rcr*r/Fsp
Eÿýü
 
 
ùE$   >r/z
int | None)rr1cCsjt |||¡dkrtdƒ‚|dkr:t|tƒs:t|tƒs:d}tj||||id\}}t||d}t||dS)a»
    Return a fixed frequency PeriodIndex.
 
    The day (calendar) is the default frequency.
 
    Parameters
    ----------
    start : str or period-like, default None
        Left bound for generating periods.
    end : str or period-like, default None
        Right bound for generating periods.
    periods : int, default None
        Number of periods to generate.
    freq : str or DateOffset, optional
        Frequency alias. By default the freq is taken from `start` or `end`
        if those are Period objects. Otherwise, the default is ``"D"`` for
        daily frequency.
    name : str, default None
        Name of the resulting PeriodIndex.
 
    Returns
    -------
    PeriodIndex
 
    Notes
    -----
    Of the three parameters: ``start``, ``end``, and ``periods``, exactly two
    must be specified.
 
    To learn more about the frequency strings, please see `this link
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.
 
    Examples
    --------
    >>> pd.period_range(start='2017-01-01', end='2018-01-01', freq='M')
    PeriodIndex(['2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06',
             '2017-07', '2017-08', '2017-09', '2017-10', '2017-11', '2017-12',
             '2018-01'],
            dtype='period[M]')
 
    If ``start`` or ``end`` are ``Period`` objects, they will be used as anchor
    endpoints for a ``PeriodIndex`` with frequency matching that of the
    ``period_range`` constructor.
 
    >>> pd.period_range(start=pd.Period('2017Q1', freq='Q'),
    ...                 end=pd.Period('2017Q2', freq='Q'), freq='M')
    PeriodIndex(['2017-03', '2017-04', '2017-05', '2017-06'],
                dtype='period[M]')
    rgzOOf the three parameters: start, end, and periods, exactly two must be specifiedNÚD)rVr"r=)ÚcomZcount_not_nonerirNr    rrSr/)rBr|rr!r>rr)r)r*Ú period_rangeås4ÿ rŒ)NNNNN)=Ú
__future__rrrÚtypingrÚnumpyrTZ pandas._libsrr3Zpandas._libs.tslibsrrr    r
r Zpandas._typingr r rZpandas.util._decoratorsrrZpandas.core.dtypes.commonrZpandas.core.dtypes.dtypesrZpandas.core.dtypes.genericrZpandas.core.dtypes.missingrZpandas.core.arrays.periodrrrrZpandas.core.commonÚcoreÚcommonr‹Zpandas.core.indexes.baseZindexesrYZibaserZ pandas.core.indexes.datetimelikerZpandas.core.indexes.datetimesrrZpandas.core.indexes.extensionrÚdictZ_index_doc_kwargsÚupdater‡r+Z
_field_opsr/rŒr)r)r)r*Ú<module>sP          
ÿ ý ÿ