AnomalyLab 0.3.0__tar.gz → 0.3.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.
- {anomalylab-0.3.0 → anomalylab-0.3.2/AnomalyLab.egg-info}/PKG-INFO +1 -1
- {anomalylab-0.3.0/AnomalyLab.egg-info → anomalylab-0.3.2}/PKG-INFO +1 -1
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/core/core.py +1 -2
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/fillna.py +16 -7
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/structure/panel_data.py +2 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/visualization/format.py +34 -3
- {anomalylab-0.3.0 → anomalylab-0.3.2}/setup.py +1 -1
- {anomalylab-0.3.0 → anomalylab-0.3.2}/.gitattributes +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/.github/workflows/python-publish.yml +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/.gitignore +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/AnomalyLab.egg-info/SOURCES.txt +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/AnomalyLab.egg-info/dependency_links.txt +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/AnomalyLab.egg-info/requires.txt +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/AnomalyLab.egg-info/top_level.txt +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/LICENSE +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/MANIFEST.in +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/README.md +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/config.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/core/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/datasets/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/datasets/dataset.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/datasets/panel_data.csv +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/datasets/time_series_data.csv +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/datasets/transition_matrix.png +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/correlation.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/empirical.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/factor_return.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/fm_regression.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/persistence.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/portfolio.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/empirical/summary.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/normalize.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/outliers.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/preprocessor.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/shift.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/preprocess/truncate.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/structure/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/structure/data.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/structure/time_series.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/utils/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/utils/imports.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/utils/utils.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/anomalylab/visualization/__init__.py +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/requirements.txt +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/setup.cfg +0 -0
- {anomalylab-0.3.0 → anomalylab-0.3.2}/tests/__init__.py +0 -0
|
@@ -121,8 +121,7 @@ class Panel:
|
|
|
121
121
|
|
|
122
122
|
@property
|
|
123
123
|
def fm_preprocessor(self) -> FamaMacBethRegression:
|
|
124
|
-
|
|
125
|
-
self._fm_preprocessor = FamaMacBethRegression(panel_data=self.panel_data)
|
|
124
|
+
self._fm_preprocessor = FamaMacBethRegression(panel_data=self.panel_data)
|
|
126
125
|
return self._fm_preprocessor
|
|
127
126
|
|
|
128
127
|
def format_preprocessor(self, path: str) -> FormatExcel:
|
|
@@ -201,12 +201,15 @@ class FillNa(Preprocessor):
|
|
|
201
201
|
|
|
202
202
|
def _warning(self, fill_columns: list[str]) -> None:
|
|
203
203
|
"""
|
|
204
|
-
|
|
204
|
+
Emit warnings regarding missing values and normalization status.
|
|
205
205
|
|
|
206
|
-
This method
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
This method performs the following checks:
|
|
207
|
+
1. It verifies if there are any missing values in the specified `fill_columns`.
|
|
208
|
+
- If no missing values are found, a warning is issued indicating this.
|
|
209
|
+
2. It checks whether the data has already been normalized.
|
|
210
|
+
- If normalized, a warning is issued that missing values were filled with zeros during normalization.
|
|
211
|
+
3. It checks whether missing values were filled previously.
|
|
212
|
+
- If so, a warning is issued to indicate that missing values have already been handled earlier.
|
|
210
213
|
|
|
211
214
|
Args:
|
|
212
215
|
fill_columns (list[str]): The list of columns to check for missing values.
|
|
@@ -215,7 +218,11 @@ class FillNa(Preprocessor):
|
|
|
215
218
|
warnings.warn(message=f"Missing values not found in {fill_columns}.")
|
|
216
219
|
if self.panel_data.normalize:
|
|
217
220
|
warnings.warn(
|
|
218
|
-
message=f"The data has already been normalized and
|
|
221
|
+
message=f"The data has already been normalized, and missing values have been filled with 0."
|
|
222
|
+
)
|
|
223
|
+
if self.panel_data.fillna:
|
|
224
|
+
warnings.warn(
|
|
225
|
+
message=f"The missing values have already been handled earlier."
|
|
219
226
|
)
|
|
220
227
|
|
|
221
228
|
|
|
@@ -224,7 +231,9 @@ if __name__ == "__main__":
|
|
|
224
231
|
|
|
225
232
|
df: DataFrame = DataSet.get_panel_data()
|
|
226
233
|
|
|
227
|
-
panel: PanelData = PanelData(
|
|
234
|
+
panel: PanelData = PanelData(
|
|
235
|
+
df=df, name="Stocks", ret="return", classifications="industry"
|
|
236
|
+
)
|
|
228
237
|
|
|
229
238
|
fill_nan: FillNa = FillNa(panel_data=panel)
|
|
230
239
|
fill_nan.fill_group_column(
|
|
@@ -182,6 +182,8 @@ class PanelData(Data):
|
|
|
182
182
|
raise ValueError("No classifications found.")
|
|
183
183
|
check_columns = set(self.classifications)
|
|
184
184
|
elif check_range == "characteristics":
|
|
185
|
+
if self.firm_characteristics is None:
|
|
186
|
+
raise ValueError("No firm characteristics found.")
|
|
185
187
|
check_columns = set(self.firm_characteristics)
|
|
186
188
|
else:
|
|
187
189
|
raise ValueError("Invalid check_range value.")
|
|
@@ -3,7 +3,7 @@ from anomalylab.utils.imports import *
|
|
|
3
3
|
|
|
4
4
|
@dataclass
|
|
5
5
|
class FormatExcel:
|
|
6
|
-
"""Class to format Excel files by adjusting cell alignment and
|
|
6
|
+
"""Class to format Excel files by adjusting cell alignment, borders, and column widths.
|
|
7
7
|
|
|
8
8
|
Attributes:
|
|
9
9
|
path (str): The directory or file path of the Excel file(s) to format.
|
|
@@ -92,15 +92,44 @@ class FormatExcel:
|
|
|
92
92
|
elif direction == "to_round":
|
|
93
93
|
cell.value = cell.value.replace("[", "(").replace("]", ")")
|
|
94
94
|
|
|
95
|
+
def auto_adjust_column_widths(self):
|
|
96
|
+
"""Automatically adjusts the column widths to fit the contents."""
|
|
97
|
+
for ws in self.wb.worksheets:
|
|
98
|
+
for column in ws.columns:
|
|
99
|
+
max_length = 0
|
|
100
|
+
col_letter = column[0].column_letter # Get the column letter
|
|
101
|
+
for cell in column:
|
|
102
|
+
try:
|
|
103
|
+
cell_length = sum(
|
|
104
|
+
2 if ord(char) > 127 else 1 for char in str(cell.value)
|
|
105
|
+
)
|
|
106
|
+
max_length = max(max_length, cell_length)
|
|
107
|
+
except:
|
|
108
|
+
pass
|
|
109
|
+
# Adjust for header row
|
|
110
|
+
# header_cell = ws[f"{col_letter}1"]
|
|
111
|
+
# if header_cell.value:
|
|
112
|
+
# max_length = max(max_length, len(str(header_cell.value)))
|
|
113
|
+
adjusted_width = max_length + 2 # Add some padding to the width
|
|
114
|
+
ws.column_dimensions[col_letter].width = adjusted_width
|
|
115
|
+
|
|
95
116
|
def save(self):
|
|
96
117
|
"""Saves the currently loaded workbook to its file path."""
|
|
97
118
|
self.wb.save(self.file_path)
|
|
98
119
|
|
|
99
|
-
def process(
|
|
120
|
+
def process(
|
|
121
|
+
self, align=True, line=True, convert_brackets=False, adjust_col_widths=False
|
|
122
|
+
):
|
|
100
123
|
"""Processes and formats Excel files.
|
|
101
124
|
|
|
102
125
|
- If the provided path is a directory, it formats all Excel files in that directory.
|
|
103
126
|
- If the provided path is a file, it formats that specific Excel file.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
align (bool): Whether to apply text alignment. Default is True.
|
|
130
|
+
line (bool): Whether to apply borders. Default is True.
|
|
131
|
+
convert_brackets (bool): Whether to convert brackets. Default is False.
|
|
132
|
+
auto_adjust (bool): Whether to adjust column widths. Default is False.
|
|
104
133
|
"""
|
|
105
134
|
files_to_process = (
|
|
106
135
|
glob(os.path.join(self.path, "*.xlsx"))
|
|
@@ -116,10 +145,12 @@ class FormatExcel:
|
|
|
116
145
|
self.line()
|
|
117
146
|
if convert_brackets:
|
|
118
147
|
self.convert_brackets()
|
|
148
|
+
if adjust_col_widths:
|
|
149
|
+
self.auto_adjust_column_widths()
|
|
119
150
|
self.save()
|
|
120
151
|
|
|
121
152
|
|
|
122
153
|
if __name__ == "__main__":
|
|
123
154
|
path = "..."
|
|
124
155
|
excel_formatter = FormatExcel(path)
|
|
125
|
-
excel_formatter.process(
|
|
156
|
+
excel_formatter.process()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|