direl-ts-tool-kit 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: direl-ts-tool-kit
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A toolbox for time series analysis and visualization.
5
5
  Home-page: https://gitlab.com/direl/direl_tool_kit
6
- Author: Tu Nombre Aquí
6
+ Author: Diego Restrepo-Leal
7
7
  Author-email: diegorestrepoleal@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
@@ -17,6 +17,7 @@ License-File: LICENCE
17
17
  Requires-Dist: pandas>=1.0.0
18
18
  Requires-Dist: numpy>=1.18.0
19
19
  Requires-Dist: matplotlib>=3.0.0
20
+ Requires-Dist: openpyxl
20
21
  Dynamic: author
21
22
  Dynamic: author-email
22
23
  Dynamic: classifier
@@ -1,2 +1,3 @@
1
1
  from .plot.plot_style import *
2
2
  from .plot.plot_ts import *
3
+ from .utilities.data_prep import *
@@ -41,6 +41,16 @@ def plot_time_series(
41
41
  -----
42
42
  Major grid lines are displayed with a dashed line ('--'), and minor grid
43
43
  lines are displayed with a dotted line (':') for detailed temporal analysis.
44
+
45
+ Available Colors
46
+ ----------------
47
+ The 'color' parameter accepts any key from the 'paper_colors' dictionary.
48
+
49
+ Lines: 'BLUE_LINES', 'ORANGE_LINES', 'GREEN_LINES', 'RED_LINES',
50
+ 'GRAY_LINES', 'PURPLE_LINES', 'MAROON_LINES', 'GOLD_LINES'.
51
+
52
+ Bars: 'BLUE_BARS', 'ORANGE_BARS', 'GREEN_BARS', 'RED_BARS',
53
+ 'GRAY_BARS', 'PURPLE_BARS', 'MAROON_BARS', 'GOLD_BARS'.
44
54
  """
45
55
 
46
56
  fig, ax = plt.subplots()
@@ -97,3 +107,43 @@ def plot_time_series(
97
107
  ax.grid(which="major", alpha=0.8, linestyle="--")
98
108
 
99
109
  return fig
110
+
111
+
112
+ def save_figure(
113
+ fig,
114
+ file_name,
115
+ variable_name="",
116
+ path="./",
117
+ ):
118
+ """
119
+ Saves a Matplotlib figure in three common high-quality formats (PNG, PDF, SVG).
120
+
121
+ The function creates a consistent file name structure:
122
+ {path}/{file_name}_{variable_name}.{extension}.
123
+
124
+ Parameters
125
+ ----------
126
+ fig : matplotlib.figure.Figure
127
+ The Matplotlib figure object to be saved.
128
+ file_name : str
129
+ The primary name for the file (e.g., 'timeseries_report').
130
+ variable_name : str, optional
131
+ An optional secondary name, often the name of the plotted variable,
132
+ to be appended to the file name. Defaults to "".
133
+ path : str, optional
134
+ The directory path where the figure files will be saved.
135
+ Defaults to the current directory ('./').
136
+
137
+ Returns
138
+ -------
139
+ None
140
+ """
141
+
142
+ if variable_name:
143
+ base_name = f"{path}/{file_name}_{variable_name}"
144
+ else:
145
+ base_name = f"{path}/{file_name}"
146
+
147
+ fig.savefig(f"{base_name}.png")
148
+ fig.savefig(f"{base_name}.pdf")
149
+ fig.savefig(f"{base_name}.svg")
@@ -0,0 +1 @@
1
+ from .data_prep import *
@@ -0,0 +1,35 @@
1
+ import pandas as pd
2
+
3
+
4
+ def parse_datetime_index(df_raw, date_column="date"):
5
+ """
6
+ Parses a specified column into datetime objects and sets it as the DataFrame index.
7
+
8
+ This function is crucial for preparing raw data (df_raw) for time series analysis
9
+ by ensuring the DataFrame is indexed by the correct datetime type.
10
+
11
+ Parameters
12
+ ----------
13
+ df_raw : pd.DataFrame
14
+ The raw DataFrame containing the data, including the column with date strings.
15
+ date_column : str, optional
16
+ The name of the column in 'df_raw' that contains the date/time information.
17
+ Defaults to "date".
18
+
19
+ Returns
20
+ -------
21
+ df_ts : pd.DataFrame
22
+ A copy of the original DataFrame with the specified date column removed
23
+ and set as the DatetimeIndex. Ready for time series plotting.
24
+ original_dates : pd.Series
25
+ The original Series containing the date strings/objects, which was used
26
+ to create the new index.
27
+ """
28
+
29
+ date_parsed = pd.to_datetime(df_raw[date_column])
30
+ df_ts = df_raw.copy()
31
+ original_dates = df_raw[date_column]
32
+ df_ts.drop(columns=[date_column], inplace=True)
33
+ df_ts.set_index(date_parsed, inplace=True)
34
+
35
+ return df_ts, original_dates
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: direl-ts-tool-kit
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A toolbox for time series analysis and visualization.
5
5
  Home-page: https://gitlab.com/direl/direl_tool_kit
6
- Author: Tu Nombre Aquí
6
+ Author: Diego Restrepo-Leal
7
7
  Author-email: diegorestrepoleal@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
@@ -17,6 +17,7 @@ License-File: LICENCE
17
17
  Requires-Dist: pandas>=1.0.0
18
18
  Requires-Dist: numpy>=1.18.0
19
19
  Requires-Dist: matplotlib>=3.0.0
20
+ Requires-Dist: openpyxl
20
21
  Dynamic: author
21
22
  Dynamic: author-email
22
23
  Dynamic: classifier
@@ -9,4 +9,6 @@ direl_ts_tool_kit.egg-info/requires.txt
9
9
  direl_ts_tool_kit.egg-info/top_level.txt
10
10
  direl_ts_tool_kit/plot/__init__.py
11
11
  direl_ts_tool_kit/plot/plot_style.py
12
- direl_ts_tool_kit/plot/plot_ts.py
12
+ direl_ts_tool_kit/plot/plot_ts.py
13
+ direl_ts_tool_kit/utilities/__init__.py
14
+ direl_ts_tool_kit/utilities/data_prep.py
@@ -1,3 +1,4 @@
1
1
  pandas>=1.0.0
2
2
  numpy>=1.18.0
3
3
  matplotlib>=3.0.0
4
+ openpyxl
@@ -2,11 +2,11 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="direl-ts-tool-kit",
5
- version="0.2.0",
5
+ version="0.2.2",
6
6
  description="A toolbox for time series analysis and visualization.",
7
7
  long_description=open("README.md", encoding="utf-8").read(),
8
8
  long_description_content_type="text/markdown",
9
- author="Tu Nombre Aquí",
9
+ author="Diego Restrepo-Leal",
10
10
  author_email="diegorestrepoleal@gmail.com",
11
11
  url="https://gitlab.com/direl/direl_tool_kit",
12
12
  packages=find_packages(),
@@ -14,6 +14,7 @@ setup(
14
14
  "pandas>=1.0.0",
15
15
  "numpy>=1.18.0",
16
16
  "matplotlib>=3.0.0",
17
+ "openpyxl",
17
18
  ],
18
19
  classifiers=[
19
20
  "Programming Language :: Python :: 3",