aplr 10.18.0__cp313-cp313-macosx_11_0_arm64.whl → 10.18.1__cp313-cp313-macosx_11_0_arm64.whl

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.

Potentially problematic release.


This version of aplr might be problematic. Click here for more details.

aplr/aplr.py CHANGED
@@ -22,6 +22,9 @@ class BaseAPLR:
22
22
  """Common preprocessing for fit and predict."""
23
23
  is_dataframe_input = isinstance(X, pd.DataFrame)
24
24
 
25
+ if X_names is not None:
26
+ X_names = list(X_names)
27
+
25
28
  if not is_dataframe_input:
26
29
  try:
27
30
  X_numeric = np.array(X, dtype=np.float64)
@@ -35,11 +38,11 @@ class BaseAPLR:
35
38
  X.columns = X_names
36
39
  else:
37
40
  X.columns = [f"X{i}" for i in range(X.shape[1])]
38
- elif hasattr(self, "X_names_") and len(self.X_names_) == X.shape[1]:
41
+ elif self.X_names_ and len(self.X_names_) == X.shape[1]:
39
42
  X.columns = self.X_names_
40
43
  else: # X is already a DataFrame
41
44
  X = X.copy() # Always copy to avoid modifying original
42
- if not is_fitting and hasattr(self, "X_names_"):
45
+ if not is_fitting and self.X_names_:
43
46
  # Check if input columns for prediction match training columns (before OHE)
44
47
  if set(X.columns) != set(self.X_names_):
45
48
  raise ValueError(
@@ -52,11 +55,18 @@ class BaseAPLR:
52
55
  self.categorical_features_ = list(
53
56
  X.select_dtypes(include=["category", "object"]).columns
54
57
  )
58
+ # Ensure it's an empty list if no categorical features, not None
59
+ if not self.categorical_features_:
60
+ self.categorical_features_ = []
55
61
 
62
+ # Apply OHE if categorical_features_ were found during fitting.
56
63
  if self.categorical_features_:
57
64
  X = pd.get_dummies(X, columns=self.categorical_features_, dummy_na=False)
58
65
  if is_fitting:
59
66
  self.ohe_columns_ = list(X.columns)
67
+ # Ensure it's an empty list if no OHE columns, not None
68
+ if not self.ohe_columns_:
69
+ self.ohe_columns_ = []
60
70
  else:
61
71
  missing_cols = set(self.ohe_columns_) - set(X.columns)
62
72
  for c in missing_cols:
@@ -65,13 +75,17 @@ class BaseAPLR:
65
75
 
66
76
  if is_fitting:
67
77
  self.na_imputed_cols_ = [col for col in X.columns if X[col].isnull().any()]
78
+ # Ensure it's an empty list if no NA imputed columns, not None
79
+ if not self.na_imputed_cols_:
80
+ self.na_imputed_cols_ = []
68
81
 
82
+ # Apply NA indicator if na_imputed_cols_ were found during fitting.
69
83
  if self.na_imputed_cols_:
70
84
  for col in self.na_imputed_cols_:
71
85
  X[col + "_missing"] = X[col].isnull().astype(int)
72
86
 
73
- if not is_fitting:
74
- for col in self.median_values_:
87
+ if not is_fitting and self.median_values_:
88
+ for col in self.median_values_: # Iterate over keys if it's a dict
75
89
  if col in X.columns:
76
90
  X[col] = X[col].fillna(self.median_values_[col])
77
91
 
@@ -131,11 +145,30 @@ class BaseAPLR:
131
145
  def _preprocess_X_predict(self, X):
132
146
  X = self._common_X_preprocessing(X, is_fitting=False)
133
147
 
134
- if hasattr(self, "final_training_columns_"):
148
+ # Enforce column order from training if it was set.
149
+ if self.final_training_columns_:
135
150
  X = X[self.final_training_columns_]
136
151
 
137
152
  return X.values.astype(np.float64)
138
153
 
154
+ def __setstate__(self, state):
155
+ """Handles unpickling for backward compatibility."""
156
+ self.__dict__.update(state)
157
+
158
+ # For backward compatibility, initialize new attributes to None if they don't exist,
159
+ # indicating the model was trained before these features were introduced.
160
+ new_attributes = [
161
+ "X_names_",
162
+ "categorical_features_",
163
+ "ohe_columns_",
164
+ "na_imputed_cols_",
165
+ "median_values_",
166
+ "final_training_columns_",
167
+ ]
168
+ for attr in new_attributes:
169
+ if not hasattr(self, attr):
170
+ setattr(self, attr, None)
171
+
139
172
 
140
173
  class APLRRegressor(BaseAPLR):
141
174
  def __init__(
@@ -261,6 +294,7 @@ class APLRRegressor(BaseAPLR):
261
294
  self.ohe_columns_ = []
262
295
  self.na_imputed_cols_ = []
263
296
  self.X_names_ = []
297
+ self.final_training_columns_ = []
264
298
 
265
299
  # Creating aplr_cpp and setting parameters
266
300
  self.APLRRegressor = aplr_cpp.APLRRegressor()
@@ -702,6 +736,7 @@ class APLRClassifier(BaseAPLR):
702
736
  self.ohe_columns_ = []
703
737
  self.na_imputed_cols_ = []
704
738
  self.X_names_ = []
739
+ self.final_training_columns_ = []
705
740
 
706
741
  # Creating aplr_cpp and setting parameters
707
742
  self.APLRClassifier = aplr_cpp.APLRClassifier()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aplr
3
- Version: 10.18.0
3
+ Version: 10.18.1
4
4
  Summary: Automatic Piecewise Linear Regression
5
5
  Home-page: https://github.com/ottenbreit-data-science/aplr
6
6
  Author: Mathias von Ottenbreit
@@ -0,0 +1,8 @@
1
+ aplr_cpp.cpython-313-darwin.so,sha256=qv4YzdT3eZcx9wRcMxaPCuXe362yTQDYPK1IoKGyD8c,1287248
2
+ aplr/__init__.py,sha256=rRfTgNWnYZlFatyA920lWqBcjwmQUI7FcvEPFUTJgzE,20
3
+ aplr/aplr.py,sha256=YOXF2a5CpC6kYoLGaDOaYIXMSRrWtSwvrbxpjYzPyA0,42653
4
+ aplr-10.18.1.dist-info/RECORD,,
5
+ aplr-10.18.1.dist-info/WHEEL,sha256=oqGJCpG61FZJmvyZ3C_0aCv-2mdfcY9e3fXvyUNmWfM,136
6
+ aplr-10.18.1.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
7
+ aplr-10.18.1.dist-info/METADATA,sha256=K58dgj9x29PL6AfrxUF0vVn5zzkGHTpfsC6Ecf4tKgY,1014
8
+ aplr-10.18.1.dist-info/licenses/LICENSE,sha256=g4qcQtkSVPHtGRi3T93DoFCrssvW6ij_emU-2fj_xfY,1113
Binary file
@@ -1,8 +0,0 @@
1
- aplr_cpp.cpython-313-darwin.so,sha256=Sj6p2pHpQI2MZlAD7QUCFkJ_DRhJzWHeerFSctp_Fx0,1287040
2
- aplr-10.18.0.dist-info/RECORD,,
3
- aplr-10.18.0.dist-info/WHEEL,sha256=oqGJCpG61FZJmvyZ3C_0aCv-2mdfcY9e3fXvyUNmWfM,136
4
- aplr-10.18.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
5
- aplr-10.18.0.dist-info/METADATA,sha256=4YERQqnfAIlutdHOvlJOaRi2tlFE4kIRKPmNGgO2uDw,1014
6
- aplr-10.18.0.dist-info/licenses/LICENSE,sha256=g4qcQtkSVPHtGRi3T93DoFCrssvW6ij_emU-2fj_xfY,1113
7
- aplr/__init__.py,sha256=rRfTgNWnYZlFatyA920lWqBcjwmQUI7FcvEPFUTJgzE,20
8
- aplr/aplr.py,sha256=cEI63m6-5U1VVou-CfKIQ85ys0DL8rqi9ghWFBK3BxY,41090
File without changes