-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix pd.to_numeric
to have consistent behavior for date-like arguments
#43315
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
Conversation
pd.to_numeric
to have consistent behavior for date-like arguments
pd.to_numeric
to have consistent behavior for date-like argumentspd.to_numeric
to have consistent behavior for date-like arguments
Test that the function returns the same results for list and pd.Series
i thing already data is consider as object , then why you again defining as a 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.
See #43280 (comment) as the behavior here is largely correct.
If you would like to address the other bugs noted there, that would be great!
@@ -137,6 +141,15 @@ def to_numeric(arg, errors="raise", downcast=None): | |||
if errors not in ("ignore", "raise", "coerce"): | |||
raise ValueError("invalid error value specified") | |||
|
|||
# Handle inputs of "date" type as objects |
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.
umm what is this?
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 idea was to change the behavior of pd.to_datetime
for date-like objects. Refer to this discussion: #43280 (comment)
result = to_numeric(lis, **kwargs) | ||
expected = to_numeric(ser, **kwargs).values | ||
|
||
tm.assert_numpy_array_equal(result, expected) |
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.
why are you comparing vs a numpy array?
these should use assert_series_equal at a minimum
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.
Because one input was a list
and the other input was a pd.Series
. So the first ouput is a np.array
and the output for series.values
is a np.array
when series
is instance of pd.Series
. It could have been done in other way tough;
...
result = to_numeric(lis, **kwargs)
expected = to_numeric(ser, **kwargs)
tm.assert_series_equal(pd.Series(result), expected)
@@ -372,39 +417,6 @@ def test_str(data, exp, transform_assert_equal): | |||
assert_equal(result, expected) | |||
|
|||
|
|||
def test_datetime_like(tz_naive_fixture, transform_assert_equal): |
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.
why are you removing these?
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.
Because I was changing the behavior of the function for date-like objects
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
Thanks for the PR but as mentioned in #43280 (comment), this will probably need a different approach. Closing due to being stale |
pd.to_numeric
has an inconsistent behavior fordatetime
objects #43280pd.to_numeric
was having an inconsistent behavior when using in datelike objects and was returning wrong result when using withpd.NaT
In master:
In this PR:
Please let me know if this approach makes sense so I can add the tests.