code: def test_calculated_aes():
      # after_stat('ae')
      mapping1 = aes("x", y=after_stat("density"))
      mapping2 = aes("x", y=after_stat("density*2"))
      mapping3 = aes("x", y=after_stat("density + count"))
      mapping4 = aes("x", y=after_stat("func(density)"))
  
      def _test():
          assert list(mapping1._calculated.keys()) == ["y"]
          assert list(mapping2._calculated.keys()) == ["y"]
          assert list(mapping3._calculated.keys()) == ["y"]
          assert list(mapping4._calculated.keys()) == ["y"]
  
          assert mapping1["y"].after_stat == "density"
          assert mapping2["y"].after_stat == "density*2"
          assert mapping3["y"].after_stat == "density + count"
          assert mapping4["y"].after_stat == "func(density)"
  
          assert mapping1._calculated["y"] == "density"
          assert mapping2._calculated["y"] == "density*2"
          assert mapping3._calculated["y"] == "density + count"
          assert mapping4._calculated["y"] == "func(density)"
  
      _test()
  
      # 'stat(ae)', DEPRECATED but still works
      mapping1 = aes("x", y="stat(density)")
      mapping2 = aes("x", y="stat(density*2)")
      mapping3 = aes("x", y="stat(density + count)")
      mapping4 = aes("x", y="stat(func(density))")
      _test()
  
      # '..ae..', DEPRECATED but still works
      mapping1 = aes("x", y="..density..")
      mapping2 = aes("x", y="..density..*2")
      mapping3 = aes("x", y="..density.. + ..count..")
      mapping4 = aes("x", y="func(..density..)")
      _test()
  
      data = pd.DataFrame({"x": [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]})
      p = ggplot(data) + geom_bar(
          aes(x="x", fill=after_stat("count + 2"))
      )
      p.draw_test()
  
      p = ggplot(data) + geom_bar(aes(x="x", fill="stat(count + 2)"))
      p.draw_test()
  
      p = ggplot(data) + geom_bar(aes(x="x", fill="..count.. + 2"))
      p.draw_test()
  
imports: from copy import deepcopy
  import numpy
  import pandas
  import pytest
  from plotnine import aes, after_scale, after_stat, annotate, coord_trans, facet_null, geom_bar, geom_histogram, geom_line, geom_point, ggplot, ggtitle, guides, labs, lims, scale_x_continuous, stage, stat_identity, theme, theme_gray, xlab, xlim, ylab
  from plotnine.exceptions import PlotnineError, PlotnineWarning
  from plotnine.mapping.aes import is_valid_aesthetic
label_desc: Use image node_id 10 for calling a global function with example usage: test_calculated_aes() without return types