-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Dataframe arithmatic operators don't work with Series using fill_value #61828
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
base: main
Are you sure you want to change the base?
Changes from all commits
99ae672
4e77fb7
eb12b34
7e23b65
4617108
bca56fe
7273396
4493e08
406cd15
ad9614b
5a64e5c
73d168b
13ed0d6
3d3a2a6
76a122e
1d3260e
32360a8
30d4a07
771a19c
a321daf
c79c210
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8491,7 +8491,10 @@ def to_series(right): | |
| # pass dtype to avoid doing inference, which would break consistency | ||
| # with Index/Series ops | ||
| dtype = None | ||
| if getattr(right, "dtype", None) == object: | ||
| if ( | ||
| getattr(right, "dtype", None) == "object" | ||
| or getattr(right, "dtype", None) == object | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't be necessary
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, this is here to keep the output dtype for some operations as objects. Specifically, When adding an object to another object. I can remove it if you think adding an exception for this test case is the better option. |
||
| ): | ||
| # can't pass right.dtype unconditionally as that would break on e.g. | ||
| # datetime64[h] ndarray | ||
| dtype = object | ||
|
|
@@ -8595,27 +8598,34 @@ def _maybe_align_series_as_frame(self, series: Series, axis: AxisInt): | |
| blockwise. | ||
| """ | ||
| rvalues = series._values | ||
| if not isinstance(rvalues, np.ndarray): | ||
| # TODO(EA2D): no need to special-case with 2D EAs | ||
| if rvalues.dtype in ("datetime64[ns]", "timedelta64[ns]"): | ||
| # We can losslessly+cheaply cast to ndarray | ||
| rvalues = np.asarray(rvalues) | ||
| if lib.is_np_dtype(rvalues.dtype): | ||
| # We can losslessly+cheaply cast to ndarray | ||
| # i.e. ndarray or dt64[naive], td64 | ||
| # TODO(EA2D): no need to special case with 2D EAs | ||
| rvalues = np.asarray(rvalues) | ||
|
|
||
| if axis == 0: | ||
| rvalues = rvalues.reshape(-1, 1) | ||
| else: | ||
| return series | ||
| rvalues = rvalues.reshape(1, -1) | ||
|
|
||
| if axis == 0: | ||
| rvalues = rvalues.reshape(-1, 1) | ||
| else: | ||
| rvalues = rvalues.reshape(1, -1) | ||
| rvalues = np.broadcast_to(rvalues, self.shape) | ||
| # pass dtype to avoid doing inference | ||
| df = self._constructor(rvalues, dtype=rvalues.dtype) | ||
|
|
||
| rvalues = np.broadcast_to(rvalues, self.shape) | ||
| # pass dtype to avoid doing inference | ||
| return self._constructor( | ||
| rvalues, | ||
| index=self.index, | ||
| columns=self.columns, | ||
| dtype=rvalues.dtype, | ||
| ).__finalize__(series) | ||
| else: | ||
| # GH#61581 | ||
| if axis == 0: | ||
| df = DataFrame(dict.fromkeys(range(self.shape[1]), rvalues)) | ||
| else: | ||
| nrows = self.shape[0] | ||
| df = DataFrame( | ||
| {i: rvalues[[i]].repeat(nrows) for i in range(self.shape[1])}, | ||
| dtype=rvalues.dtype, | ||
| ) | ||
| df.index = self.index | ||
| df.columns = self.columns | ||
| return df.__finalize__(series) | ||
|
|
||
| def _flex_arith_method( | ||
| self, other, op, *, axis: Axis = "columns", level=None, fill_value=None | ||
|
|
@@ -8625,11 +8635,6 @@ def _flex_arith_method( | |
| if self._should_reindex_frame_op(other, op, axis, fill_value, level): | ||
| return self._arith_method_with_reindex(other, op) | ||
|
|
||
| if isinstance(other, Series) and fill_value is not None: | ||
| # TODO: We could allow this in cases where we end up going | ||
| # through the DataFrame path | ||
| raise NotImplementedError(f"fill_value {fill_value} not supported.") | ||
|
|
||
| other = ops.maybe_prepare_scalar_for_op(other, self.shape) | ||
| self, other = self._align_for_op(other, axis, flex=True, level=level) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.