@@ -5,9 +5,7 @@ cnp.import_array()
5
5
6
6
from pandas._libs.tslibs.util cimport is_integer_object
7
7
8
- from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS
9
8
from pandas._libs.tslibs.offsets cimport is_offset_object
10
- from pandas._libs.tslibs.parsing cimport get_rule_month
11
9
12
10
# ----------------------------------------------------------------------
13
11
# Constants
@@ -333,161 +331,3 @@ cpdef int get_to_timestamp_base(int base):
333
331
elif FreqGroup.FR_HR <= base <= FreqGroup.FR_SEC:
334
332
return FreqGroup.FR_SEC
335
333
return base
336
-
337
-
338
- # ----------------------------------------------------------------------
339
- # Frequency comparison
340
-
341
- def is_subperiod (source , target ) -> bint:
342
- """
343
- Returns True if downsampling is possible between source and target
344
- frequencies
345
-
346
- Parameters
347
- ----------
348
- source : string or DateOffset
349
- Frequency converting from
350
- target : string or DateOffset
351
- Frequency converting to
352
-
353
- Returns
354
- -------
355
- is_subperiod : boolean
356
- """
357
-
358
- if target is None or source is None:
359
- return False
360
- source = _maybe_coerce_freq(source)
361
- target = _maybe_coerce_freq(target)
362
-
363
- if _is_annual(target ):
364
- if _is_quarterly(source):
365
- return _quarter_months_conform(get_rule_month(source),
366
- get_rule_month(target))
367
- return source in {' D' , ' C' , ' B' , ' M' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
368
- elif _is_quarterly(target):
369
- return source in {' D' , ' C' , ' B' , ' M' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
370
- elif _is_monthly(target):
371
- return source in {' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
372
- elif _is_weekly(target):
373
- return source in {target, ' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
374
- elif target == ' B' :
375
- return source in {' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
376
- elif target == ' C' :
377
- return source in {' C' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
378
- elif target == ' D' :
379
- return source in {' D' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
380
- elif target == ' H' :
381
- return source in {' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
382
- elif target == ' T' :
383
- return source in {' T' , ' S' , ' L' , ' U' , ' N' }
384
- elif target == ' S' :
385
- return source in {' S' , ' L' , ' U' , ' N' }
386
- elif target == ' L' :
387
- return source in {' L' , ' U' , ' N' }
388
- elif target == ' U' :
389
- return source in {' U' , ' N' }
390
- elif target == ' N' :
391
- return source in {' N' }
392
-
393
-
394
- def is_superperiod (source , target ) -> bint:
395
- """
396
- Returns True if upsampling is possible between source and target
397
- frequencies
398
-
399
- Parameters
400
- ----------
401
- source : string
402
- Frequency converting from
403
- target : string
404
- Frequency converting to
405
-
406
- Returns
407
- -------
408
- is_superperiod : boolean
409
- """
410
- if target is None or source is None:
411
- return False
412
- source = _maybe_coerce_freq(source)
413
- target = _maybe_coerce_freq(target)
414
-
415
- if _is_annual(source ):
416
- if _is_annual(target):
417
- return get_rule_month(source) == get_rule_month(target)
418
-
419
- if _is_quarterly(target):
420
- smonth = get_rule_month(source)
421
- tmonth = get_rule_month(target)
422
- return _quarter_months_conform(smonth, tmonth)
423
- return target in {' D' , ' C' , ' B' , ' M' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
424
- elif _is_quarterly(source):
425
- return target in {' D' , ' C' , ' B' , ' M' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
426
- elif _is_monthly(source):
427
- return target in {' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
428
- elif _is_weekly(source):
429
- return target in {source, ' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
430
- elif source == ' B' :
431
- return target in {' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
432
- elif source == ' C' :
433
- return target in {' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
434
- elif source == ' D' :
435
- return target in {' D' , ' C' , ' B' , ' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
436
- elif source == ' H' :
437
- return target in {' H' , ' T' , ' S' , ' L' , ' U' , ' N' }
438
- elif source == ' T' :
439
- return target in {' T' , ' S' , ' L' , ' U' , ' N' }
440
- elif source == ' S' :
441
- return target in {' S' , ' L' , ' U' , ' N' }
442
- elif source == ' L' :
443
- return target in {' L' , ' U' , ' N' }
444
- elif source == ' U' :
445
- return target in {' U' , ' N' }
446
- elif source == ' N' :
447
- return target in {' N' }
448
-
449
-
450
- cdef str _maybe_coerce_freq(code):
451
- """ we might need to coerce a code to a rule_code
452
- and uppercase it
453
-
454
- Parameters
455
- ----------
456
- source : string or DateOffset
457
- Frequency converting from
458
-
459
- Returns
460
- -------
461
- code : string
462
- """
463
- assert code is not None
464
- if is_offset_object(code):
465
- # i.e. isinstance(code, DateOffset):
466
- code = code.rule_code
467
- return code.upper()
468
-
469
-
470
- cdef bint _quarter_months_conform(str source, str target):
471
- snum = c_MONTH_NUMBERS[source]
472
- tnum = c_MONTH_NUMBERS[target]
473
- return snum % 3 == tnum % 3
474
-
475
-
476
- cdef bint _is_annual(str rule):
477
- rule = rule.upper()
478
- return rule == ' A' or rule.startswith(' A-' )
479
-
480
-
481
- cdef bint _is_quarterly(str rule):
482
- rule = rule.upper()
483
- return rule == ' Q' or rule.startswith(' Q-' ) or rule.startswith(' BQ' )
484
-
485
-
486
- cdef bint _is_monthly(str rule):
487
- rule = rule.upper()
488
- return rule == ' M' or rule == ' BM'
489
-
490
-
491
- cdef bint _is_weekly(str rule):
492
- rule = rule.upper()
493
- return rule == ' W' or rule.startswith(' W-' )
0 commit comments