Skip to content

Commit 3942af5

Browse files
MaxGhenisclaude
andcommitted
Deprecate set_weight_col() in favor of set_weights()
- Add deprecation warning to set_weight_col() (Fixes #208) - Add test for set_weights() with string column name argument - set_weights() already handles both array and string inputs - Users should use set_weights(column_name) instead of set_weight_col(column_name) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 21fe555 commit 3942af5

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

changelog_entry.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
- __getattr__ method to MicroDataFrame for intuitive column access via dot notation (Fixes #220)
99
- Full pandas argument support to drop() and merge() methods (Addresses #212)
1010
- nullify_weights() method to both MicroDataFrame and MicroSeries to set all weights to 1 (Fixes #176)
11+
- Test coverage for set_weights() with string column name argument
12+
deprecated:
13+
- set_weight_col() method - use set_weights() with a string argument instead (Fixes #208)

microdf/microdataframe.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,23 @@ def set_weight_col(
225225
"""Sets the weights for the MicroDataFrame by specifying the name of
226226
the weight column.
227227
228-
:param weights: Array of weights.
228+
.. deprecated:: 1.0.2
229+
Use :meth:`set_weights` with a string argument instead.
230+
This method will be removed in a future version.
231+
232+
:param column: Name of the column to use as weights.
229233
:param preserve_old: If True, keeps the old weights as a column when
230234
new weights are provided.
231-
:type weights: np.array
235+
:type column: str
232236
"""
237+
import warnings
238+
warnings.warn(
239+
"set_weight_col is deprecated and will be removed in a future version. "
240+
"Use set_weights(column_name) instead.",
241+
DeprecationWarning,
242+
stacklevel=2
243+
)
244+
233245
if preserve_old and self.weights_col is not None:
234246
self["old_" + self.weights_col] = self.weights
235247

microdf/tests/test_microseries_dataframe.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def test_df_init() -> None:
2222
df["w"] = w
2323
df.set_weight_col("w")
2424
assert df.a.mean() == np.average(arr, weights=w)
25+
26+
# Test set_weights with string (column name)
27+
df2 = mdf.MicroDataFrame()
28+
df2["a"] = arr
29+
df2["w"] = w
30+
df2.set_weights("w") # Using string column name instead of set_weight_col
31+
assert df2.a.mean() == np.average(arr, weights=w)
32+
assert np.array_equal(df2.weights.values, w)
2533

2634

2735
def test_handles_empty_index() -> None:

0 commit comments

Comments
 (0)