Skip to content

Commit 6d90a43

Browse files
chrisaycockjreback
authored andcommitted
BUG: use entire size of DatetimeTZBlock when coercing result (pandas-dev#15855) (pandas-dev#15924)
* BUG: use entire size of DatetimeTZBlock when coercing result (pandas-dev#15855) * Moved test * Removed unnecessary 'self' * Removed unnecessary 'self', again
1 parent 5d17a94 commit 6d90a43

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ Conversion
11441144
- Bug in ``DataFrame.fillna()`` where the argument ``downcast`` was ignored when fillna value was of type ``dict`` (:issue:`15277`)
11451145
- Bug in ``.asfreq()``, where frequency was not set for empty ``Series`` (:issue:`14320`)
11461146
- Bug in ``DataFrame`` construction with nulls and datetimes in a list-like (:issue:`15869`)
1147+
- Bug in ``DataFrame.fillna()`` with tz-aware datetimes (:issue:`15855`)
11471148

11481149
Indexing
11491150
^^^^^^^^

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ def _try_coerce_result(self, result):
24752475
if isinstance(result, np.ndarray):
24762476
# allow passing of > 1dim if its trivial
24772477
if result.ndim > 1:
2478-
result = result.reshape(len(result))
2478+
result = result.reshape(np.prod(result.shape))
24792479
result = self.values._shallow_copy(result)
24802480

24812481
return result

pandas/tests/frame/test_missing.py

+14
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ def test_fillna(self):
257257
result = df.fillna(value={'Date': df['Date2']})
258258
assert_frame_equal(result, expected)
259259

260+
# with timezone
261+
# GH 15855
262+
df = pd.DataFrame({'A': [pd.Timestamp('2012-11-11 00:00:00+01:00'),
263+
pd.NaT]})
264+
exp = pd.DataFrame({'A': [pd.Timestamp('2012-11-11 00:00:00+01:00'),
265+
pd.Timestamp('2012-11-11 00:00:00+01:00')]})
266+
assert_frame_equal(df.fillna(method='pad'), exp)
267+
268+
df = pd.DataFrame({'A': [pd.NaT,
269+
pd.Timestamp('2012-11-11 00:00:00+01:00')]})
270+
exp = pd.DataFrame({'A': [pd.Timestamp('2012-11-11 00:00:00+01:00'),
271+
pd.Timestamp('2012-11-11 00:00:00+01:00')]})
272+
assert_frame_equal(df.fillna(method='bfill'), exp)
273+
260274
def test_fillna_downcast(self):
261275
# GH 15277
262276
# infer int64 from float64

pandas/tests/series/test_missing.py

+12
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ def test_datetime64_tz_fillna(self):
258258
self.assert_series_equal(expected, result)
259259
self.assert_series_equal(pd.isnull(s), null_loc)
260260

261+
# with timezone
262+
# GH 15855
263+
df = pd.Series([pd.Timestamp('2012-11-11 00:00:00+01:00'), pd.NaT])
264+
exp = pd.Series([pd.Timestamp('2012-11-11 00:00:00+01:00'),
265+
pd.Timestamp('2012-11-11 00:00:00+01:00')])
266+
assert_series_equal(df.fillna(method='pad'), exp)
267+
268+
df = pd.Series([pd.NaT, pd.Timestamp('2012-11-11 00:00:00+01:00')])
269+
exp = pd.Series([pd.Timestamp('2012-11-11 00:00:00+01:00'),
270+
pd.Timestamp('2012-11-11 00:00:00+01:00')])
271+
assert_series_equal(df.fillna(method='bfill'), exp)
272+
261273
def test_datetime64tz_fillna_round_issue(self):
262274
# GH 14872
263275

0 commit comments

Comments
 (0)