Skip to content

BUG: tz_localize(UTC) not making a copy #46460

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 2 commits into from
Mar 22, 2022

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@jreback jreback added the Timezones Timezone data dtype label Mar 21, 2022
@jreback jreback added this to the 1.5 milestone Mar 21, 2022
@jbrockmendel
Copy link
Member Author

I think thats the test that #46450 fixed

times = ["2015-03-08 01:00", "2015-03-08 02:00", "2015-03-08 03:00"]
index = DatetimeIndex(times)

res = index.tz_localize("UTC")
Copy link
Member

@mroeschke mroeschke Mar 22, 2022

Choose a reason for hiding this comment

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

Probably good to test with utc_fixture.

Also based on the code change None also returns a copy now too (and should be tested)?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. will use the fixture in the index tests and do the None just once in the tslibs tests

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.

Warrants a whatsnew?

@jreback jreback merged commit 1d90a59 into pandas-dev:main Mar 22, 2022
@jbrockmendel jbrockmendel deleted the bug-tz_localize-utc-copy branch March 22, 2022 23:25
@mroeschke
Copy link
Member

You may be aware, but looks like this PR didn't fully pass the CI checks

https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=75723&view=logs&jobId=f64eb602-b0ed-5dcc-0a60-a7288ad39597&j=f64eb602-b0ed-5dcc-0a60-a7288ad39597&t=129bd72d-2137-55bd-1811-c4ce50c6dce8

_______________________ test_tz_localize_to_utc_copies ________________________
[gw1] win32 -- Python 3.8.12 C:\Miniconda\envs\pandas-dev\python.exe

    def test_tz_localize_to_utc_copies():
        # GH#46460
        arr = np.arange(5, dtype="i8")
        result = tzconversion.tz_convert_from_utc(arr, tz=UTC)
        tm.assert_numpy_array_equal(result, arr)
        assert not np.shares_memory(arr, result)
    
>       result = tzconversion.tz_convert_from_utc(arr, tz=None)

pandas\tests\tslibs\test_conversion.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas\_libs\tslibs\tzconversion.pyx:506: in pandas._libs.tslibs.tzconversion.tz_convert_from_utc
    converted = _tz_convert_from_utc(vals, tz)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   local_val = utc_val + deltas[pos]
E   UnboundLocalError: local variable 'deltas' referenced before assignment

pandas\_libs\tslibs\tzconversion.pyx:571: UnboundLocalError

@jbrockmendel
Copy link
Member Author

yah, #46478 includes a fix

@jbrockmendel
Copy link
Member Author

also #46489 is a targeted fix

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

Successfully merging this pull request may close these issues.

3 participants