Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[BUG] RandomUnderSampler throws errors if pandas DataFrame has timestamps #970

Closed
@tomateit

Description

@tomateit

Describe the bug

RandomUnderSampler performs checks onX argument, which are unnecessary, as they do not affect the choice of resampled indices.
This is an issue if I pass pandas DataFrame.
The exception is not risen if I pass a numpy object with timestamps.

Steps/Code to Reproduce

from datetime import datetimeimport pandas as pddf = pd.DataFrame({"label": [0,0,0,1], "td": [datetime.now()]*4})rus = imblearn.under_sampling.RandomUnderSampler(random_state=2342374)rus.fit_resample(df, df.label)

Expected Results

No error is thrown.

Actual Results

TypeError: The DType <class 'numpy.dtype[int64]'> could not be promoted by <class 'numpy.dtype[datetime64]'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtype[int64]'>, <class 'numpy.dtype[datetime64]'>)

Versions

Linux-5.15.0-60-generic-x86_64-with-glibc2.35Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]NumPy 1.24.1SciPy 1.9.3Scikit-Learn 1.2.1Imbalanced-Learn 0.10.0

My current workaround

from datetime import datetimeimport pandas as pddf = pd.DataFrame({"label": [0,0,0,1], "td": [datetime.now()]*4})rus = imblearn.under_sampling.RandomUnderSampler(random_state=2342374)downsabpled_df, _ = rus.fit_resample(df.to_numpy(), df.label)downsabpled_df = pd.DataFrame(downsabpled_df, columns=df.columns)

P.S. Huge thanks for this useful library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp