question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

COMPAT: Scalar types immutable

See original GitHub issue

My impression (discussion somewhere on gitter) is that pd.Period is supposed to be immutable. That would certainly make sense for objects going into a PeriodIndex.

per = pd.Period('2014Q1')
>>> per
Period('2014Q1', 'Q-DEC')

freq = per.freq.copy()
freq.n *= 2
per.freq = freq
>>> per
Period('2014Q1', '2Q-DEC')

per.freq is a DateOffset object*, which is defined in tseries.offsets. There is a comment in tseries.offsets.BusinessHourMixin.apply saying “# calculate here because offset is not immutable”.

So a couple of questions:

  1. Are we sure pd.Period should be immutable? If so, is there a preferred way of imposing that? Note that the class is defined in a .pyx file and some methods explicitly call __new__.
  2. Does the comment about offset not being immutable mean that it can’t or shouldn’t be? Outside of __init__ and __setstate__, the only place in tseries.offsets where I see any self.foo attributes being set is self.daytime = False in BusinessHourMixin._get_business_hours_by_sec. grepping for “daytime”, this attribute does not appear to be referenced anywhere else.

* BTW, I think DateOffset is one of a small number of commonly-used classes for which there is not a ABCDateOffset equivalent. Is that by design? If not, I’ll be happy to make one.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
jbrockmendelcommented, Jun 22, 2018

Possibly closed by #21341

0reactions
jbrockmendelcommented, Jul 11, 2018

Closed by #17239 and #21341

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which types are mutable and immutable in the Google Go ...
Then the answer is: Integer variables are mutable, integer values are immutable. This view is consistent with the Go specification which states ...
Read more >
proposal: Go 2: immutable type qualifier · Issue #27975 - GitHub
This issue describes a language feature proposal to Immutable Types. It targets the current Go 1.x (> 1.11) language specification and ...
Read more >
Immutable - Android Developers
data classes that only contain val properties that do not have custom getters can safely be marked as Immutable if the types of...
Read more >
What do you really know about Variables, Data Types and ...
It's about a variable (re)assignment. Immutability is when “an object's state cannot be modified after it is created” whereas Mutability refers to “an...
Read more >
Complete immutability and Object Oriented Programming
3. Immutability can be simulated in an OOP language, by only exposing object access points as methods or read-only properties that do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found