anishmehta24 opened a new issue, #41732:
URL: https://github.com/apache/beam/issues/41732
### What happened?
`min()` and `max()` on a deferred Series or DataFrame fail, or give a wrong
result, when one partition is empty or has only missing values:
```python
import apache_beam as beam
import pandas as pd
from apache_beam.dataframe.transforms import DataframeTransform
parts = [
pd.DataFrame({'t': pd.to_timedelta([1, 5], unit='s')}),
pd.DataFrame({'t': pd.to_timedelta([None, None])}, index=[2, 3]),
]
with beam.Pipeline() as p:
_ = (
p | beam.Create(parts)
| DataframeTransform(
lambda df: df.t.min(),
proxy=parts[0].iloc[:0],
yield_elements='pandas')
| beam.Map(print))
# pandas gives Timedelta('0 days 00:00:01'), Beam raises
# TypeError: '<=' not supported between instances of 'Timedelta' and 'float'
```
tz-aware datetime and `string` columns fail the same way, and
`max(skipna=False)` on an `Int64` column raises `TypeError: boolean value of NA
is ambiguous`. With `skipna=False` an empty partition also breaks float
columns: for parts `pd.DataFrame({'x': [10.0, 30.0]})` and `pd.DataFrame({'x':
[1.0, 2.0]}, index=[2, 3])`, `df[df.x > 5].x.max(skipna=False)` gives `nan`
instead of `30.0`. Seen on 2.77.0 and on master.
In `DeferredSeries.aggregate`, each partition's min or max goes through
`pd.Series(...)`, which turns a `NaT` or `NA` result into a datetime64 or
object Series that can't be combined with the other partitions. An empty
partition gives NaN, even with `skipna=False`.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] Component: Python SDK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]