Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

[Feature] Adding renameSome method for selectively renaming multiple columns at once #91

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

anusha5695
Copy link

PR for #90

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 94.76% when pulling 86d1061 on anusha5695:renameSome into 6ad744a on Gmousse:develop.

@Gmousse
Copy link
Owner

Gmousse commented Jul 25, 2019

Hi @anusha5695,
Thank you for this PR ! That's clean !
Just fix the few details (nothing about mechanics, just about notation).
To conclude that's a great job.

I think I will create another PR in order to complete your work and apply what I said about the .rename method.

The aim is:

  • add this functionnality in the rename method
  • deprecate the .renameAll
  • don't add a new method (we have already a ton of methods :D)

I hope you can review this.

@anusha5695
Copy link
Author

anusha5695 commented Jul 25, 2019

Hi @Gmousse: Okay. Can i pick that if that's not a problem?

@anusha5695
Copy link
Author

And this - "Just fix the few details (nothing about mechanics, just about notation)" . What should be fixed? I ll put them in the next commits.

@Gmousse
Copy link
Owner

Gmousse commented Jul 25, 2019

Hey ! Of course you can pick it. Go Go ! :)

What should be fixed ?

Just the few comments I made about doc, or code style. Sorry, that was not clear :D.

@anusha5695
Copy link
Author

Cool. will push the changes over the weekend

@anusha5695 anusha5695 closed this Jul 29, 2019
@anusha5695 anusha5695 reopened this Jul 29, 2019
@anusha5695
Copy link
Author

anusha5695 commented Jul 29, 2019

Hi @Gmousse : I guess the dist and bin folder would be built. Right?

Also have pushed in the new changes. Please review :)

@anusha5695
Copy link
Author

Hi @Gmousse have you started reviewing the changes?

Copy link
Owner

@Gmousse Gmousse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems nice.

But, just keep in mind that "deprecated" is not "deleted".

See my comments to have more informations.

@@ -757,6 +757,23 @@ class DataFrame {
return this.renameAll(newColumnNames);
}

/**
* Rename selective columns.
* @param {Map} columnsMap Key value pairs of columns to rename and new column names of the DataFrame.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing Map (in the description) by an Object.

Indeed, it could confuse the users with the real Map type https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map.

* df.renameSome({'column1':'columnA', 'column3':'columnB', 'column50':'columnC'])
*/
renameSome(columnsMap) {
let availableColumnNames = this[__columns__];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid mutations in the current DataFrame by setting the array index, consider to use:

const availableColumnNames = Array.from(this[__columns__]);

let availableColumnNames = this[__columns__];
Object.entries(columnsMap).forEach(([key,value])=>{
let position = availableColumnNames.indexOf(key);
position > -1 && (availableColumnNames[position] = value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (position > -1) {
    availableColumnNames[position] = value
}

Your syntax is good, but it could confuse newcomers. Prefer to use a simple if statement in this case.

.renameSome({})
.listColumns(),
["c2", "c3", "c4"],
"renamed selectively"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the description by something like:

renamed nothing if the payload is empty.

* @example
* df.renameAll(['column1', 'column3', 'column4'])
*/
renameAll(newColumnNames) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renameAll must not be deleted but deprecated.
It means that the method must remain and will be deleted on the next major version (2.0.0).
Moreover the method must throw a warning when used.

* @example
* df.rename('column1', 'columnRenamed')
*/
rename(columnName, replacement) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current usage of rename must be kept.
Indeed we deprecate this usage (we don't delete it completely).
The renameAll must not be deleted but deprecated.
It means that the method must remain compatible with the current usage.The current usage will be completely deleted on the next major version (2.0.0).
Moreover the method must throw a warning when used with the current usage.

As a solution, you can check if columnsMap is an object or a string.
If it's a string you could kept the current usage.
Else use your new usage.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(However you can update the docstring with your new usage)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Gmousse Sorry I'm a lil confused.

As a solution, you can check if columnsMap is an object or a string.
If it's a string you could kept the current usage.
Else use your new usage

Didn't understand the above. Is it for rename or renameAll? cuz rename takes 2 params currently.

Sorry for the back and forth questions

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi !
Sorry to be late !

I was talking about .rename. Indeed we will handle parameters in order to ensure compatibility.

Example of implementation:

rename(mapping, deprecatedParam) {
    if (typeof mapping === "string") {
         // old behaviour
    } else {
        // your behaviour
    }
}

assert.deepEqual(
df
.select("c2", "c3", "c4")
.renameAll(["c16", "c17", "c18"])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this test until the real deprecation (on major version...)

@Gmousse
Copy link
Owner

Gmousse commented Aug 7, 2019

Hi ! sorry to be late :D (I was busy and the vacation doesn't help)

You can now read my review

@anusha5695
Copy link
Author

Hi @Gmousse : Sorry to bother on a vacation :D . Looked at the comments. Will make changes and push over the weekend

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants