Skip to content

Remove FutureWarnings due to pandas 2.0 - #157

Merged
patrickleonardy merged 4 commits into
developfrom
156-fixing-futurewarnings
May 12, 2023
Merged

Remove FutureWarnings due to pandas 2.0#157
patrickleonardy merged 4 commits into
developfrom
156-fixing-futurewarnings

Conversation

@patrickleonardy

@patrickleonardy patrickleonardy commented Apr 4, 2023

Copy link
Copy Markdown
Contributor

Story Title

Fixing FutureWarnings (#156)

Changes made

  • Changes the syntax of assigning a new column from df.loc[:,"col_name"] = something to df["col_name"] = something
  • Replaces the depreciated inplace argument for some methods

How does the solution address the problem

This PR will update the syntax

Comment

No test were written to automatically catch FutureWarnings. FutureWarnings are displayed by default so they are already shown when running the tests.

Linked issues

Resolves #156
Linked to #160

@patrickleonardy patrickleonardy linked an issue Apr 4, 2023 that may be closed by this pull request

@pietrodantuono pietrodantuono left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The black formatting of tests/preprocessing/test_target_encoder.py is out of the scope of this pull request. I suggest to undo this formatting before going further with the PR.

Also, sometimes, specially in testing or when defining 2D arrays, you may want to avoid black formatting to compromise readability and conciseness, e.g.

# yapf (Google-like option)
df = pd.DataFrame({'variable': ['positive', 'positive', 'negative',
                                'neutral', 'negative', 'positive',
                                'negative', 'neutral', 'neutral',
                                'neutral', 'positive'],
                   'target': [5, 4, -5, 0, -4, 5, -5, 0, 1, 0, 4]})

VS

# black
df = pd.DataFrame(
    {
        "variable": [
            "positive",
            "positive",
            "negative",
            "neutral",
            "negative",
            "positive",
            "negative",
            "neutral",
            "neutral",
            "neutral",
            "positive",
        ],
        "target": [5, 4, -5, 0, -4, 5, -5, 0, 1, 0, 4],
    }
)

To avoid for specific code chunks being automatically formatted by black, you can set:

# fmt: off
df = pd.DataFrame({'variable': ['positive', 'positive', 'negative',
                                'neutral', 'negative', 'positive',
                                'negative', 'neutral', 'neutral',
                                'neutral', 'positive'],
                   'target': [5, 4, -5, 0, -4, 5, -5, 0, 1, 0, 4]})
# fmt: on

Also, I see that there are more than one df.append commands in the tests. All of these will raise a FutureWarning, and if your intention is to get rid of them, these should be changed to pd.concat.

@patrickleonardy

Copy link
Copy Markdown
Contributor Author

@pietrodantuono
I changed back the formatting in the test file and also adapted code that outputted the FutureWarnings append and .loc[:, "col_name"] =).

@sandervh14 sandervh14 changed the title Remove FutureWarnings due to pandas Remove FutureWarnings due to pandas 2.0 Apr 6, 2023
@sandervh14
sandervh14 requested review from ZlaTanskY and removed request for ZlaTanskY April 6, 2023 13:43
@patrickleonardy patrickleonardy linked an issue Apr 7, 2023 that may be closed by this pull request
@patrickleonardy patrickleonardy linked an issue Apr 7, 2023 that may be closed by this pull request
@sandervh14 sandervh14 linked an issue Apr 7, 2023 that may be closed by this pull request
@sandervh14 sandervh14 added this to the 2023-04 milestone Apr 7, 2023
@patrickleonardy
patrickleonardy merged commit 3d1692f into develop May 12, 2023
@sandervh14 sandervh14 modified the milestones: 2023-04, 2023-05 May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long term pandas==2.0 support: adapt unsupported pandas usages Fixing FutureWarnings

4 participants