-
Notifications
You must be signed in to change notification settings - Fork 116
updating #1169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updating #1169
Changes from all commits
23b3976
1865e79
e185808
a1e721b
2a7c50e
8157830
74126e2
b213147
65f70d0
e4c0ff6
2289b78
69a84b6
935c567
8383809
2f7a702
d539991
8b4e131
fcdfd1d
6816c74
bb8c1e9
bb186ec
559bbbd
5fe779b
4f40a4b
7fa55ce
a9f45e1
cef932c
23e48ab
3837ec7
5cb7d16
996b2f9
254ca05
73c691a
f48bd83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -601,33 +601,100 @@ def drop( | |
| self, | ||
| labels: str | int | list | None = None, | ||
| axis: Literal["index", "columns", "origin", "development"] | int = 1, | ||
| index: str | int | list | None = None, | ||
| columns: str | int | list | None = None, | ||
| origin: str | int | list | None = None, | ||
| development: str | int | list | None = None, | ||
| ) -> Triangle: | ||
| """Drop specified labels from rows or columns. | ||
|
|
||
| Remove rows or columns by specifying label names and corresponding axis, | ||
| or by specifying directly index or column names. | ||
| Remove labels by specifying label names and corresponding axis, or by | ||
| specifying directly ``index``, ``columns``, ``origin``, or | ||
| ``development`` names. | ||
|
|
||
| Parameters | ||
| ----------- | ||
|
|
||
| labels: str | int | list | None | ||
| Index or column labels to drop. | ||
| Index or column labels to drop. A single label or list-like. | ||
|
|
||
| axis: {0 or ‘index’, 1 or ‘columns’}, default 1 | ||
| Whether to drop labels from the index (0 or ‘index’) | ||
| or columns (1 or ‘columns’). | ||
| axis: {0 or ‘index’, 1 or ‘columns’, 2 or 'origin', 3 or 'development'}, default 1 | ||
| The axis to drop ``labels`` from. | ||
|
|
||
| index: str | int | list | None | ||
| Alternative to ``axis=0``. Equivalent to ``labels, axis=0``. | ||
|
|
||
| columns: str | int | list | None | ||
| Alternative to ``axis=1``. Equivalent to ``labels, axis=1``. | ||
|
|
||
| origin: str | int | list | None | ||
| Alternative to ``axis=2``. Equivalent to ``labels, axis=2``. | ||
|
|
||
| development: str | int | list | None | ||
| Alternative to ``axis=3``. Equivalent to ``labels, axis=3``. | ||
|
|
||
| Returns | ||
| ------- | ||
| Triangle | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| Drop a single column with the ``labels``/``axis`` form or the | ||
| ``columns`` alternative; the two are equivalent. | ||
|
|
||
| .. testsetup:: | ||
|
|
||
| import chainladder as cl | ||
|
|
||
| .. testcode:: | ||
|
|
||
| tri = cl.load_sample('clrd') | ||
| print(tri.columns.tolist()) | ||
| print(tri.drop(columns='CumPaidLoss').columns.tolist()) | ||
|
|
||
| .. testoutput:: | ||
|
|
||
| ['IncurLoss', 'CumPaidLoss', 'BulkLoss', 'EarnedPremDIR', 'EarnedPremCeded', 'EarnedPremNet'] | ||
| ['IncurLoss', 'BulkLoss', 'EarnedPremDIR', 'EarnedPremCeded', 'EarnedPremNet'] | ||
|
|
||
| A list of labels can be dropped from an axis as well. | ||
|
|
||
| .. testcode:: | ||
|
|
||
| print(tri.drop(columns=['CumPaidLoss', 'IncurLoss']).columns.tolist()) | ||
|
|
||
| .. testoutput:: | ||
|
|
||
| ['BulkLoss', 'EarnedPremDIR', 'EarnedPremCeded', 'EarnedPremNet'] | ||
|
|
||
| """ | ||
| axis = self._get_axis(axis) | ||
| labels = [labels] if type(labels) is str else list(labels) | ||
| if axis == 1: | ||
| return self[[item for item in self.columns if item not in labels]] | ||
| alternatives = {0: index, 1: columns, 2: origin, 3: development} | ||
| if any(value is not None for value in alternatives.values()): | ||
| if labels is not None: | ||
| raise ValueError( | ||
| "Cannot specify both 'labels' and any of 'index', " | ||
| "'columns', 'origin', or 'development'." | ||
| ) | ||
| to_drop = { | ||
| ax: value for ax, value in alternatives.items() if value is not None | ||
| } | ||
| else: | ||
| raise NotImplementedError("Triangle.drop() only implemented for column axis.") | ||
| to_drop = {self._get_axis(axis): labels} | ||
| result = self | ||
| for ax, ax_labels in to_drop.items(): | ||
| ax_labels = ( | ||
| [ax_labels] if np.isscalar(ax_labels) else list(ax_labels) | ||
| ) | ||
| if ax == 1: | ||
| result = result[ | ||
| [item for item in result.columns if item not in ax_labels] | ||
| ] | ||
| else: | ||
| raise NotImplementedError( | ||
| "Triangle.drop() only implemented for column axis." | ||
| ) | ||
| return result | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop() silently no-ops without labelsLow Severity When Reviewed by Cursor Bugbot for commit f48bd83. Configure here. |
||
|
|
||
| @property | ||
| def T(self) -> DataFrame: # noqa: N802 | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI concurrency cancels unrelated PRs
Medium Severity
The new concurrency
groupkeys ongithub.head_ref, so pull requests from different forks that share a common branch name (for examplepatch-1orfix) land in the same group. Withcancel-in-progress: true, one contributor’s run can cancel another’s unrelated checks.Reviewed by Cursor Bugbot for commit f48bd83. Configure here.