Skip to content

Data

ts_stat_tests.utils.data πŸ”—

Summary

This module contains utility functions to load classic time series datasets for testing and demonstration purposes.

It provides interfaces for both synthetic data generation (random numbers, sine waves, trends) and external data loading from common benchmarks.

SEED module-attribute πŸ”—

SEED: int = 42

get_random_generator cached πŸ”—

get_random_generator(seed: int) -> RandomGenerator

Summary

Generates a NumPy random number generator with a specified seed for reproducibility.

Details

This function returns a numpy.random.Generator instance using default_rng. This is the recommended way to generate random numbers in modern NumPy (v1.17+).

Parameters:

Name Type Description Default
seed int

The seed value for the random number generator.

required

Returns:

Type Description
Generator

A NumPy random number generator initialized with the given seed.

Examples
Setup
1
>>> from ts_stat_tests.utils.data import get_random_generator
Example 1: Creating a RandomGenerator
1
2
3
4
5
>>> rng = get_random_generator(42)
>>> print(rng is not None)
True
>>> print(type(rng))
<class 'numpy.random._generator.Generator'>
References
  1. NumPy Random Generator
Source code in src/ts_stat_tests/utils/data.py
 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
@lru_cache
@typechecked
def get_random_generator(seed: int) -> RandomGenerator:
    r"""
    !!! note "Summary"
        Generates a NumPy random number generator with a specified seed for reproducibility.

    ???+ abstract "Details"
        This function returns a `numpy.random.Generator` instance using `default_rng`. This is the recommended way to generate random numbers in modern NumPy (v1.17+).

    Params:
        seed (int):
            The seed value for the random number generator.

    Returns:
        (RandomGenerator):
            A NumPy random number generator initialized with the given seed.

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_random_generator

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Creating a RandomGenerator"}
        >>> rng = get_random_generator(42)
        >>> print(rng is not None)
        True
        >>> print(type(rng))
        <class 'numpy.random._generator.Generator'>

        ```

    ??? question "References"
        1. [NumPy Random Generator](https://numpy.org/doc/stable/reference/random/generator.html)

    """
    return np.random.default_rng(seed)

get_random_numbers cached πŸ”—

get_random_numbers(seed: int) -> NDArray[np.float64]

Summary

Generates an array of random numbers with a specified seed for reproducibility.

Details

Generates a 1D array of 1000 random floating-point numbers distributed uniformly in the half-open interval \([0.0, 1.0)\).

Parameters:

Name Type Description Default
seed int

The seed value for the random number generator.

required

Returns:

Type Description
NDArray[float64]

An array of random numbers with shape (1000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_random_numbers
>>> data = get_random_numbers(42)
Example 1: Generating Random Numbers
1
2
3
4
5
6
7
8
>>> print(data.shape)
(1000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[0.77395605 0.43887844 0.85859792 0.69736803 0.09417735]
References
  1. NumPy Random Generator
Source code in src/ts_stat_tests/utils/data.py
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
@lru_cache
@typechecked
def get_random_numbers(seed: int) -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates an array of random numbers with a specified seed for reproducibility.

    ???+ abstract "Details"
        Generates a 1D array of 1000 random floating-point numbers distributed uniformly in the half-open interval $[0.0, 1.0)$.

    Params:
        seed (int):
            The seed value for the random number generator.

    Returns:
        (NDArray[np.float64]):
            An array of random numbers with shape (1000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_random_numbers
        >>> data = get_random_numbers(42)

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating Random Numbers"}
        >>> print(data.shape)
        (1000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [0.77395605 0.43887844 0.85859792 0.69736803 0.09417735]

        ```

    ??? question "References"
        1. [NumPy Random Generator](https://numpy.org/doc/stable/reference/random/generator.html)

    """
    rng: RandomGenerator = get_random_generator(seed)
    return rng.random(size=1000)

get_random_numbers_2d cached πŸ”—

get_random_numbers_2d(seed: int) -> NDArray[np.float64]

Summary

Generates a 2D array of random numbers with a specified seed for reproducibility.

Details

Produces a 2D matrix of shape \((4, 3000)\) containing uniform random values.

Parameters:

Name Type Description Default
seed int

The seed value for the random number generator.

required

Returns:

Type Description
NDArray[float64]

A 2D array of random numbers with shape (4, 3000).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_random_numbers_2d
>>> data = get_random_numbers_2d(42)
Example 1: Generating 2D Random Numbers
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
>>> print(data.shape)
(4, 3000)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:, :5])
[[0.06206311 0.45826204 0.12903006 0.15232671 0.63228281]
 [0.71609997 0.3571156  0.85186786 0.24097716 0.53839349]
 [0.74315144 0.90157433 0.59866347 0.52857443 0.89016256]
 [0.72072839 0.71123776 0.20269503 0.0366554  0.30379952]]
References
  1. NumPy Random Generator
Source code in src/ts_stat_tests/utils/data.py
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
224
225
226
227
228
229
230
231
@lru_cache
@typechecked
def get_random_numbers_2d(seed: int) -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates a 2D array of random numbers with a specified seed for reproducibility.

    ???+ abstract "Details"
        Produces a 2D matrix of shape $(4, 3000)$ containing uniform random values.

    Params:
        seed (int):
            The seed value for the random number generator.

    Returns:
        (NDArray[np.float64]):
            A 2D array of random numbers with shape (4, 3000).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_random_numbers_2d
        >>> data = get_random_numbers_2d(42)

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating 2D Random Numbers"}
        >>> print(data.shape)
        (4, 3000)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:, :5])
        [[0.06206311 0.45826204 0.12903006 0.15232671 0.63228281]
         [0.71609997 0.3571156  0.85186786 0.24097716 0.53839349]
         [0.74315144 0.90157433 0.59866347 0.52857443 0.89016256]
         [0.72072839 0.71123776 0.20269503 0.0366554  0.30379952]]

        ```

    ??? question "References"
        1. [NumPy Random Generator](https://numpy.org/doc/stable/reference/random/generator.html)

    """
    rng: RandomGenerator = get_random_generator(seed)
    return rng.random(size=(4, 3000))

get_sine_wave cached πŸ”—

get_sine_wave() -> NDArray[np.float64]

Summary

Generates a sine wave dataset.

Details

Produces a 1D array of 1000 samples of a sine wave with amplitude 1.0 and period 1000.

Returns:

Type Description
NDArray[float64]

An array representing a sine wave with shape (3000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_sine_wave
>>> data = get_sine_wave()
Example 1: Generating a Sine Wave
1
2
3
4
5
6
7
8
>>> print(data.shape)
(3000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[0.         0.06279052 0.12533323 0.18738131 0.24868989]
References
  1. NumPy Trigonometric Functions
Source code in src/ts_stat_tests/utils/data.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
@lru_cache
@typechecked
def get_sine_wave() -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates a sine wave dataset.

    ???+ abstract "Details"
        Produces a 1D array of 1000 samples of a sine wave with amplitude 1.0 and period 1000.

    Returns:
        (NDArray[np.float64]):
            An array representing a sine wave with shape (3000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_sine_wave
        >>> data = get_sine_wave()

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating a Sine Wave"}
        >>> print(data.shape)
        (3000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [0.         0.06279052 0.12533323 0.18738131 0.24868989]

        ```

    ??? question "References"
        1. [NumPy Trigonometric Functions](https://numpy.org/doc/stable/reference/routines.math.html#trigonometric-functions)

    """
    return np.sin(2 * np.pi * 1 * np.arange(3000) / 100)

get_normal_curve cached πŸ”—

get_normal_curve(seed: int) -> NDArray[np.float64]

Summary

Generates a normal distribution curve dataset.

Details

Draws 1000 samples from a standard Gaussian distribution.

Parameters:

Name Type Description Default
seed int

The seed value for the random number generator.

required

Returns:

Type Description
NDArray[float64]

An array representing a normal distribution curve with shape (1000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_normal_curve
>>> data = get_normal_curve(42)
Example 1: Generating Normal Curve Data
1
2
3
4
5
6
7
8
>>> print(data.shape)
(1000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[ 0.12993113 -0.75691222 -0.33007356 -1.88579735 -0.37064992]
References
  1. NumPy Random Normal
Source code in src/ts_stat_tests/utils/data.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
@lru_cache
@typechecked
def get_normal_curve(seed: int) -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates a normal distribution curve dataset.

    ???+ abstract "Details"
        Draws 1000 samples from a standard Gaussian distribution.

    Params:
        seed (int):
            The seed value for the random number generator.

    Returns:
        (NDArray[np.float64]):
            An array representing a normal distribution curve with shape (1000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_normal_curve
        >>> data = get_normal_curve(42)

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating Normal Curve Data"}
        >>> print(data.shape)
        (1000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [ 0.12993113 -0.75691222 -0.33007356 -1.88579735 -0.37064992]

        ```

    ??? question "References"
        1. [NumPy Random Normal](https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.normal.html)

    """
    rng: RandomGenerator = get_random_generator(seed)
    return rng.normal(loc=0.0, scale=1.0, size=1000)

get_straight_line cached πŸ”—

get_straight_line() -> NDArray[np.float64]

Summary

Generates a straight line dataset.

Details

Returns a sequence of integers from 0 to 999.

Returns:

Type Description
NDArray[float64]

An array representing a straight line with shape (1000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_straight_line
>>> data = get_straight_line()
Example 1: Generating Straight Line Data
1
2
3
4
5
6
7
8
>>> print(data.shape)
(1000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[0. 1. 2. 3. 4.]
References
  1. NumPy Arange
Source code in src/ts_stat_tests/utils/data.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
@lru_cache
@typechecked
def get_straight_line() -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates a straight line dataset.

    ???+ abstract "Details"
        Returns a sequence of integers from 0 to 999.

    Returns:
        (NDArray[np.float64]):
            An array representing a straight line with shape (1000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_straight_line
        >>> data = get_straight_line()

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating Straight Line Data"}
        >>> print(data.shape)
        (1000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [0. 1. 2. 3. 4.]

        ```

    ??? question "References"
        1. [NumPy Arange](https://numpy.org/doc/stable/reference/generated/numpy.arange.html)

    """
    return np.arange(1000).astype(np.float64)

get_trend_data cached πŸ”—

get_trend_data() -> NDArray[np.float64]

Summary

Generates trend data.

Details

Generates an array with a linear trend by combining two ramp functions.

Returns:

Type Description
NDArray[float64]

An array representing trend data with shape (1000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_trend_data
>>> data = get_trend_data()
Example 1: Generating Trend Data
1
2
3
4
5
6
7
8
>>> print(data.shape)
(1000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[0.  1.5 3.  4.5 6. ]
References
  1. NumPy Arange
Source code in src/ts_stat_tests/utils/data.py
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
@lru_cache
@typechecked
def get_trend_data() -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates trend data.

    ???+ abstract "Details"
        Generates an array with a linear trend by combining two ramp functions.

    Returns:
        (NDArray[np.float64]):
            An array representing trend data with shape (1000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_trend_data
        >>> data = get_trend_data()

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating Trend Data"}
        >>> print(data.shape)
        (1000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [0.  1.5 3.  4.5 6. ]

        ```

    ??? question "References"
        1. [NumPy Arange](https://numpy.org/doc/stable/reference/generated/numpy.arange.html)

    """
    return np.arange(1000) + 0.5 * np.arange(1000)

get_uniform_data cached πŸ”—

get_uniform_data(seed: int) -> NDArray[np.float64]

Summary

Generates uniform random data with a specified seed for reproducibility.

Details

Returns a 1D array of 1000 samples from a uniform distribution.

Parameters:

Name Type Description Default
seed int

The seed value for the random number generator.

required

Returns:

Type Description
NDArray[float64]

An array of uniform random data with shape (1000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_uniform_data
>>> data = get_uniform_data(42)
Example 1: Generating Uniform Data
1
2
3
4
5
6
7
8
>>> print(data.shape)
(1000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[0.80227457 0.81857128 0.87962986 0.11378193 0.29263938]
References
  1. NumPy Random Uniform
Source code in src/ts_stat_tests/utils/data.py
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
@lru_cache
@typechecked
def get_uniform_data(seed: int) -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates uniform random data with a specified seed for reproducibility.

    ???+ abstract "Details"
        Returns a 1D array of 1000 samples from a uniform distribution.

    Params:
        seed (int):
            The seed value for the random number generator.

    Returns:
        (NDArray[np.float64]):
            An array of uniform random data with shape (1000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_uniform_data
        >>> data = get_uniform_data(42)

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating Uniform Data"}
        >>> print(data.shape)
        (1000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [0.80227457 0.81857128 0.87962986 0.11378193 0.29263938]

        ```

    ??? question "References"
        1. [NumPy Random Uniform](https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.uniform.html)

    """
    rng: RandomGenerator = get_random_generator(seed)
    return rng.uniform(low=0.0, high=1.0, size=1000)

get_noise_data cached πŸ”—

get_noise_data(seed: int) -> NDArray[np.float64]

Summary

Generates fractional Gaussian noise data with a specified seed for reproducibility.

Details

Uses the stochastic library to sample fractional Gaussian noise with a Hurst exponent of 0.5, effectively producing white noise.

Parameters:

Name Type Description Default
seed int

The seed value for the random number generator.

required

Returns:

Type Description
NDArray[float64]

An array of fractional Gaussian noise data with shape (1000,).

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import get_noise_data
>>> data = get_noise_data(42)
Example 1: Generating Noise Data
1
2
3
4
5
6
7
8
>>> print(data.shape)
(1000,)
>>> print(type(data))
<class 'numpy.ndarray'>
>>> print(data.dtype)
float64
>>> print(data[:5])
[-0.05413957 -0.0007609  -0.00177524  0.00909899 -0.03044404]
References
  1. Stochastic Library
Source code in src/ts_stat_tests/utils/data.py
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
@lru_cache
@typechecked
def get_noise_data(seed: int) -> NDArray[np.float64]:
    r"""
    !!! note "Summary"
        Generates fractional Gaussian noise data with a specified seed for reproducibility.

    ???+ abstract "Details"
        Uses the `stochastic` library to sample fractional Gaussian noise with a Hurst exponent of 0.5, effectively producing white noise.

    Params:
        seed (int):
            The seed value for the random number generator.

    Returns:
        (NDArray[np.float64]):
            An array of fractional Gaussian noise data with shape (1000,).

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import get_noise_data
        >>> data = get_noise_data(42)

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Generating Noise Data"}
        >>> print(data.shape)
        (1000,)
        >>> print(type(data))
        <class 'numpy.ndarray'>
        >>> print(data.dtype)
        float64
        >>> print(data[:5])
        [-0.05413957 -0.0007609  -0.00177524  0.00909899 -0.03044404]

        ```

    ??? question "References"
        1. [Stochastic Library](https://github.com/crflynn/stochastic)

    """
    rng: RandomGenerator = get_random_generator(seed)
    return FractionalGaussianNoise(hurst=0.5, rng=rng).sample(1000)

load_airline cached πŸ”—

load_airline() -> pd.Series

Summary

Loads the classic Airline Passengers dataset as a pandas Series.

Details

The Air Passengers dataset provides monthly totals of a US airline's international passengers from 1949 to 1960. It is a classic dataset for time series analysis, exhibiting both trend and seasonality.

Returns:

Type Description
Series

The Airline Passengers dataset.

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import load_airline
>>> data = load_airline()
Example 1: Loading Airline Data
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> print(len(data))
144
>>> print(type(data))
<class 'pandas.core.series.Series'>
>>> print(data.head())
Period
1949-01    112.0
1949-02    118.0
1949-03    132.0
1949-04    129.0
1949-05    121.0
Freq: M, Name: Number of airline passengers, dtype: float64
Credit

Inspiration from: sktime.datasets.load_airline()

References
  1. Box, G. E. P., Jenkins, G. M., Reinsel, G. C., & Ljung, G. M. (2015). Time series analysis: forecasting and control. John Wiley & Sons.
Source code in src/ts_stat_tests/utils/data.py
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
@lru_cache
@typechecked
def load_airline() -> pd.Series:
    r"""
    !!! note "Summary"
        Loads the classic Airline Passengers dataset as a pandas Series.

    ???+ abstract "Details"
        The Air Passengers dataset provides monthly totals of a US airline's international passengers from 1949 to 1960. It is a classic dataset for time series analysis, exhibiting both trend and seasonality.

    Returns:
        (pd.Series):
            The Airline Passengers dataset.

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import load_airline
        >>> data = load_airline()

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Loading Airline Data"}
        >>> print(len(data))
        144
        >>> print(type(data))
        <class 'pandas.core.series.Series'>
        >>> print(data.head())
        Period
        1949-01    112.0
        1949-02    118.0
        1949-03    132.0
        1949-04    129.0
        1949-05    121.0
        Freq: M, Name: Number of airline passengers, dtype: float64

        ```

    ??? success "Credit"
        Inspiration from: [`sktime.datasets.load_airline()`](https://www.sktime.net/en/stable/api_reference/generated/sktime.datasets.load_airline.html)

    ??? question "References"
        1. Box, G. E. P., Jenkins, G. M., Reinsel, G. C., & Ljung, G. M. (2015). Time series analysis: forecasting and control. John Wiley & Sons.

    """
    data_source = "https://raw.githubusercontent.com/sktime/sktime/main/sktime/datasets/data/Airline/Airline.csv"
    _data = pd.read_csv(data_source, index_col=0, dtype={1: float}).squeeze("columns")
    if not isinstance(_data, pd.Series):
        raise TypeError("Expected a pandas Series from the data source.")
    data: pd.Series = _data
    data.index = pd.PeriodIndex(data.index, freq="M", name="Period")
    data.name = "Number of airline passengers"
    return data

load_macrodata cached πŸ”—

load_macrodata() -> pd.DataFrame

Summary

Loads the classic Macrodata dataset as a pandas DataFrame.

Details

This dataset contains various US macroeconomic time series from 1959Q1 to 2009Q3. It includes variables such as real GDP, consumption, investment, etc.

Returns:

Type Description
DataFrame

The Macrodata dataset.

Examples
Setup
1
2
>>> from ts_stat_tests.utils.data import load_macrodata
>>> data = load_macrodata()
Example 1: Loading Macrodata
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> print(data.shape)
(203, 14)
>>> print(type(data))
<class 'pandas.core.frame.DataFrame'>
>>> print(data[["year", "quarter", "realgdp"]].head())
        year  quarter   realgdp
Period
1959Q1  1959        1  2710.349
1959Q2  1959        2  2778.801
1959Q3  1959        3  2775.488
1959Q4  1959        4  2785.204
1960Q1  1960        1  2847.699
Credit

Inspiration from: statsmodels.datasets.macrodata.load_pandas()

References
  1. R. F. Engle, D. F. Hendry, and J. F. Richard (1983). Exogeneity. Econometrica, 51(2):277–304.
Source code in src/ts_stat_tests/utils/data.py
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
@lru_cache
@typechecked
def load_macrodata() -> pd.DataFrame:
    r"""
    !!! note "Summary"
        Loads the classic Macrodata dataset as a pandas DataFrame.

    ???+ abstract "Details"
        This dataset contains various US macroeconomic time series from 1959Q1 to 2009Q3. It includes variables such as real GDP, consumption, investment, etc.

    Returns:
        (pd.DataFrame):
            The Macrodata dataset.

    ???+ example "Examples"

        ```pycon {.py .python linenums="1" title="Setup"}
        >>> from ts_stat_tests.utils.data import load_macrodata
        >>> data = load_macrodata()

        ```

        ```pycon {.py .python linenums="1" title="Example 1: Loading Macrodata"}
        >>> print(data.shape)
        (203, 14)
        >>> print(type(data))
        <class 'pandas.core.frame.DataFrame'>
        >>> print(data[["year", "quarter", "realgdp"]].head())
                year  quarter   realgdp
        Period
        1959Q1  1959        1  2710.349
        1959Q2  1959        2  2778.801
        1959Q3  1959        3  2775.488
        1959Q4  1959        4  2785.204
        1960Q1  1960        1  2847.699

        ```

    ??? success "Credit"
        Inspiration from: [`statsmodels.datasets.macrodata.load_pandas()`](https://www.statsmodels.org/stable/datasets/generated/statsmodels.datasets.macrodata.macrodata.load_pandas.html)

    ??? question "References"
        1. R. F. Engle, D. F. Hendry, and J. F. Richard (1983). Exogeneity. Econometrica, 51(2):277–304.

    """
    data_source = (
        "https://raw.githubusercontent.com/statsmodels/statsmodels/main/statsmodels/datasets/macrodata/macrodata.csv"
    )
    data: pd.DataFrame = pd.read_csv(
        data_source,
        index_col=None,
        dtype={
            "year": int,
            "quarter": int,
        },
    )
    data.index = pd.PeriodIndex(
        data=data.year.astype(str) + "Q" + data.quarter.astype(str),
        freq="Q",
        name="Period",
    )
    return data

data_airline module-attribute πŸ”—

data_airline: Series = load_airline()

data_macrodata module-attribute πŸ”—

data_macrodata: DataFrame = load_macrodata()

data_random module-attribute πŸ”—

data_random: NDArray[float64] = get_random_numbers(SEED)

data_random_2d module-attribute πŸ”—

data_random_2d: NDArray[float64] = get_random_numbers_2d(
    SEED
)

data_sine module-attribute πŸ”—

data_sine: NDArray[float64] = get_sine_wave()

data_normal module-attribute πŸ”—

data_normal: NDArray[float64] = get_normal_curve(SEED)

data_line module-attribute πŸ”—

data_line: NDArray[float64] = get_straight_line()

data_trend module-attribute πŸ”—

data_trend: NDArray[float64] = get_trend_data()

data_noise module-attribute πŸ”—

data_noise: NDArray[float64] = get_noise_data(SEED)