Skip to content

BUG: Fix #25959 - Don't call .array in DatetimeLikeArrayMixin's map #25964

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

Merged
merged 8 commits into from
May 19, 2019

Conversation

ThomasKluiters
Copy link
Contributor

@ThomasKluiters ThomasKluiters commented Apr 2, 2019

In Series.apply we call .array on returning the result of DatetimeLikeArrayMixin map, which causes an error.

@codecov
Copy link

codecov bot commented Apr 2, 2019

Codecov Report

Merging #25964 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25964      +/-   ##
==========================================
+ Coverage   91.69%   91.72%   +0.03%     
==========================================
  Files         174      174              
  Lines       50749    50754       +5     
==========================================
+ Hits        46534    46556      +22     
+ Misses       4215     4198      -17
Flag Coverage Δ
#multiple 90.23% <100%> (+0.04%) ⬆️
#single 41.69% <50%> (+0.38%) ⬆️
Impacted Files Coverage Δ
pandas/core/series.py 93.67% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/compat/__init__.py 93.54% <0%> (-0.4%) ⬇️
pandas/plotting/_style.py 76.92% <0%> (-0.26%) ⬇️
pandas/plotting/_misc.py 38.23% <0%> (-0.23%) ⬇️
pandas/core/frame.py 97.02% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.6% <0%> (-0.11%) ⬇️
pandas/plotting/_converter.py 63.66% <0%> (-0.06%) ⬇️
pandas/core/groupby/generic.py 88.96% <0%> (-0.05%) ⬇️
pandas/core/dtypes/dtypes.py 96.65% <0%> (-0.02%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5d15b2...36429a0. Read the comment docs.

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments and also needs a whatsnew entry in 0.25

@gfyoung gfyoung added Bug Timezones Timezone data dtype labels Apr 3, 2019
@ThomasKluiters
Copy link
Contributor Author

Some comments and also needs a whatsnew entry in 0.25

Added!

@pep8speaks
Copy link

pep8speaks commented Apr 4, 2019

Hello @ThomasKluiters! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-18 19:09:18 UTC

@ThomasKluiters
Copy link
Contributor Author

ThomasKluiters commented Apr 6, 2019

I don't know why the tests are failing - locally all seems fine

Edit - updating from master seemed to have resolved the issue.

@ThomasKluiters
Copy link
Contributor Author

@jreback @mroeschke I resolved my issues, could you have a look please?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Apr 9, 2019 via email

@jreback jreback added this to the 0.25.0 milestone Apr 9, 2019
@ThomasKluiters
Copy link
Contributor Author

ThomasKluiters commented Apr 9, 2019

Can you investigate what happens if we don’t cal tolist? What tests fail?

On Apr 9, 2019, at 06:00, Thomas Kluiters @.***> wrote: @ThomasKluiters commented on this pull request. In pandas/core/series.py: > @@ -3688,7 +3688,11 @@ def f(x): if len(mapped) and isinstance(mapped[0], Series): from pandas.core.frame import DataFrame - return DataFrame(mapped.tolist(), index=self.index) + # GH 25959 we don't need to call tolist + # if we've been given an ExtensionArray + if not isinstance(mapped, ExtensionArray): It was initially there - I do not know, I resolved your problem though. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Removing the tolist will make this test fail:
Relate to issue #2316
`____________________________________________________________________________ TestSeriesAggregate.test_with_nested_series ____________________________________________________________________________

self = <pandas.tests.series.test_apply.TestSeriesAggregate object at 0x12ebc31d0>
datetime_series = 2000-01-03 -1.347822
2000-01-04 0.739531
2000-01-05 0.230190
2000-01-06 -0.397356
2000-01-07 -0.128090
200...2-08 -1.054427
2000-02-09 0.360638
2000-02-10 -0.639306
2000-02-11 -0.517083
Freq: B, Name: ts, dtype: float64

def test_with_nested_series(self, datetime_series):
    # GH 2316
    # .agg with a reducer and a transform, what to do
    result = datetime_series.apply(lambda x: Series(
        [x, x ** 2], index=['x', 'x^2']))
    expected = DataFrame({'x': datetime_series,
                          'x^2': datetime_series ** 2})
  tm.assert_frame_equal(result, expected)

E AssertionError: DataFrame are different
E
E DataFrame shape mismatch
E [left]: (30, 1)
E [right]: (30, 2)
`

@TomAugspurger
Copy link
Contributor

So are we using tolist to get an array from a series? Maybe call pd.array on the object instead of tolist?

@ThomasKluiters
Copy link
Contributor Author

So are we using tolist to get an array from a series? Maybe call pd.array on the object instead of tolist?

pd.array seems to be the best solution, it removes the need to check for an EA. Any suggestions on how I can fix the conflict best in the whatsnew?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Apr 10, 2019 via email

@ThomasKluiters
Copy link
Contributor Author

extract_array

extract_array does not work I'm afraid, it will fail the same test

@jreback
Copy link
Contributor

jreback commented Apr 20, 2019

can you merge master

@jreback jreback removed this from the 0.25.0 milestone Apr 20, 2019
@ThomasKluiters
Copy link
Contributor Author

can you merge master

Done!

@jreback jreback added this to the 0.25.0 milestone Apr 28, 2019
@jreback
Copy link
Contributor

jreback commented Apr 28, 2019

can you merge master and ping on green.

@jreback
Copy link
Contributor

jreback commented May 7, 2019

you have an isort error; can you merge master and fix up. ping on green.

@ThomasKluiters
Copy link
Contributor Author

you have an isort error; can you merge master and fix up. ping on green.

Sorry, but I can't seem to find what's wrong with the build - it seems to be failing at /doc/source/reference/frame.rst - "DataFrame" has no attribute "to_panel".

@WillAyd
Copy link
Member

WillAyd commented May 7, 2019

Should be fixed after #26308

@jreback
Copy link
Contributor

jreback commented May 12, 2019

can you merge master

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments, ping on green.

@jreback
Copy link
Contributor

jreback commented May 18, 2019

linting error:

./pandas/core/series.py(3708,80): error E501: line too long (82 > 79 characters)
Bash exited with code '1'.

@jreback
Copy link
Contributor

jreback commented May 18, 2019

ping on green.

@ThomasKluiters
Copy link
Contributor Author

@jreblack ping

@jreback jreback merged commit 6cf3b5c into pandas-dev:master May 19, 2019
@jreback
Copy link
Contributor

jreback commented May 19, 2019

thanks @ThomasKluiters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.apply fails when the series is a timezone aware datetime
7 participants