-
Notifications
You must be signed in to change notification settings - Fork 6
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
More powerful setlabels #985
base: master
Are you sure you want to change the base?
More powerful setlabels #985
Conversation
…s" as labels array.set_labels({'a0:a1': 'A0..A1'}) (closes larray-project#906)
@@ -4,7 +4,7 @@ | |||
Syntax changes | |||
^^^^^^^^^^^^^^ | |||
|
|||
* renamed ``Array.old_method_name()`` to :py:obj:`Array.new_method_name()` (closes :issue:`1`). | |||
* renamed ``Axis.apply()`` and ``Axis.replace()`` are deprecated in favor of :py:obj:`Axis.set_labels()`. |
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.
s/renamed//
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.
😄
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.
Are Axis.apply()
and/or Axis.replace()
still mentioned in the api.rst file?
If yes, please remove.
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.
You made me realize I forgot to update api.rst for this PR. So yes, they are still mentioned and Axis.set_labels is not.
@@ -52,6 +52,24 @@ Miscellaneous improvements | |||
* made all I/O functions/methods/constructors to accept either a string or a pathlib.Path object | |||
for all arguments representing a path (closes :issue:`896`). | |||
|
|||
* :py:obj:`Array.set_labels()` and :py:obj:`Axis.set_labels()` (formerly ``Axis.replace()`` and ``Axis.apply()``) now |
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.
Did you check if either Axis.replace()
or Axis.apply()
was used in the tutorial?
If yes, replace it by Axis.set_labels()
please.
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.
No idea, I forgot about the tutorial.
@@ -11,8 +11,9 @@ | |||
|
|||
from larray.core.abstractbases import ABCAxis, ABCAxisReference, ABCArray | |||
from larray.core.expr import ExprNode | |||
from larray.core.group import (Group, LGroup, IGroup, IGroupMaker, _to_tick, _to_ticks, _to_key, _seq_summary, | |||
_idx_seq_to_slice, _seq_group_to_name, _translate_group_key_hdf, remove_nested_groups) | |||
from larray.core.group import (Group, LGroup, IGroup, IGroupMaker, _to_label, _to_labels, _to_key, _seq_summary, |
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.
maybe mention in the commit message that you renamed tick
as label
?
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.
ok
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.
Thx
# labels = self.labels.tolist() | ||
|
||
# using object dtype because new labels length can be larger than the fixed str length in self.labels | ||
labels = self.labels.astype(object) |
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.
Will the labels of the returned axis be always of the type object
?
What about non-string labels (e.g. int
) ?
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.
Yes, they will. That's clearly suboptimal but already better than broken labels IMO.
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.
So, maybe store the dtype in the beginning of the method and re-apply astype()
in the end in original type was not str
?
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.
That's not as easy, because we can easily get mixed types labels in the result (especially when making changes to only a subset of labels) even when the original dtype is not str. Imagine applying str.format() or whatever function which converts integers to strings.
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.
If one gets mixed types labels in the result, shouldn't we force her/him to first convert the type of the labels to str?
I'm afraid that the only case where users will get mixed types labels is when they don't realize they do.
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.
Converting everything to string is painful/surprising too. The usual case where you want a mixed type axis is when you have an integer axis (e.g. age) and you add a "total" label, or the opposite: you have a string axis with some special aggregate labels ("total", etc.) and want to convert all "number strings" to integers, but not the special labels.
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.
The usual case where you want a mixed type axis is when you have an integer axis (e.g. age) and you add a "total" label
Yes indeed. I forgot that specific case. I guess the current implementation is OK then.
@@ -343,9 +343,9 @@ def _seq_group_to_name(seq) -> Sequence[Any]: | |||
return seq | |||
|
|||
|
|||
def _to_tick(v) -> Scalar: | |||
def _to_label(v) -> Scalar: |
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.
As said in another PR, move this function and all others of the same kind to a separate module?
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.
Unsure. Will check.
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.
Except my comments LGTM.
No description provided.